I'm still relatively new to Grails. I'm developing an online survey. I keep running into issues with webflow that I can't seem to find solutions for on the web. I have a class Survey that has many Topics that has many questions. In my web flow the amount of topics and questions are dynamic depending on which survey you choose. My question is how can you iterate (in the web flow) through each of the topics and questions (sort of like an arrray or list) where I can grab specific ones and set them to the flow variable. for example I'll give my Survey and Topic class:
class Survey implements Serializable {
List topic
String surveyName
float version
static hasMany = [topic:Topic]
static constraints = {
surveyName (blank:false)
}
}
and Topic:
class Topic implements Serializable {
List primaryQuestion
String topicName
static belongsTo = [survey:Survey]
static hasMany = [primaryQuestion:PrimaryQuestion]
static constraints = {
topicName (blank:false)
}
}
So I set my flow variable
onStart {
flow.survey = Survey.get(params.id)
}
So how can I get each individual topic and question within the controller? My goal is to have one view represent each question with a "next" and previous". With my understanding of web flows I know this can be possible. I just can't figure out how to pass a single question to the view instead of iterating through all of them at the same time.