P
Pavel
Greetings to all -
I'm having some difficulty to render indexed radio input fields
correctly. The problem is that it's a "double" indexed example. The
jsp operates on the collection of the Question instances. And each
question has a list of pre-defined answers to choose from. The idea is
to list all of the questions and then collect the answers chosen. The
"list" and "text" types are working (generating both
name="questions[x].answer", where x is the index of the question) but
radio does not.
If indexed="true" is specified, then each pre-defined radio answer has
a name="questions[x].answer" WHERE x is the index of the PRE-DEFINED
ANSWER from the predefinedAnswers iterator (not from the questions
iterator).
If indexed attribute is not specified, then the input field name is
rendered just as name="answer".
There should be a way to make it work. Is nested:radio going to help
in any way ? Any suggestions are very appreciated.
Thanks
Pavel
Here is the relevant portion of the jsp:
<logic:iterate id="questions" property="questions"
name="questionSetForm">
<logic:equal name="questions" property="type" value="list">
<div>It's a list</div>
<html:select name="questions" property="answer" indexed="true">
<htmlptionsCollection name="questions"
property="predefinedAnswers" value="id" label="label"/>
</html:select>
</logic:equal>
<logic:equal name="questions" property="type" value="text">
<div>It's a text</div>
<html:text name="questions" property="answer" indexed="true" />
</logic:equal>
<logic:equal name="questions" property="type" value="radio">
<div>It's a radio choice</div>
<logic:iterate id="predefinedAnswer" property="predefinedAnswers"
name="questions">
<html:radio name="questions" property="answer" value="id"
idName="predefinedAnswer">
<bean:write name="predefinedAnswer" property="label" />
</html:radio>
</logic:iterate>
</logic:equal>
</logic:iterate>
The questionSetForm class defines only one property that hold a
collection of Question instances:
public List getQuestions() {
return questions;
}
public void setQuestions(List questions) {
this.questions = questions;
}
The Question class defines the following relevant properties (along
with corresponding get/set methods):
private Integer id = null;
private Integer questionSetId = null;
private String type = null;
//Holds the collection of the PredefinedAnswer instances
private List predefinedAnswers = null;
private String label = null;
private String answer = null;
The PredefinedAnswer class defines the id and label properties used to
render the list of choices.
I'm having some difficulty to render indexed radio input fields
correctly. The problem is that it's a "double" indexed example. The
jsp operates on the collection of the Question instances. And each
question has a list of pre-defined answers to choose from. The idea is
to list all of the questions and then collect the answers chosen. The
"list" and "text" types are working (generating both
name="questions[x].answer", where x is the index of the question) but
radio does not.
If indexed="true" is specified, then each pre-defined radio answer has
a name="questions[x].answer" WHERE x is the index of the PRE-DEFINED
ANSWER from the predefinedAnswers iterator (not from the questions
iterator).
If indexed attribute is not specified, then the input field name is
rendered just as name="answer".
There should be a way to make it work. Is nested:radio going to help
in any way ? Any suggestions are very appreciated.
Thanks
Pavel
Here is the relevant portion of the jsp:
<logic:iterate id="questions" property="questions"
name="questionSetForm">
<logic:equal name="questions" property="type" value="list">
<div>It's a list</div>
<html:select name="questions" property="answer" indexed="true">
<htmlptionsCollection name="questions"
property="predefinedAnswers" value="id" label="label"/>
</html:select>
</logic:equal>
<logic:equal name="questions" property="type" value="text">
<div>It's a text</div>
<html:text name="questions" property="answer" indexed="true" />
</logic:equal>
<logic:equal name="questions" property="type" value="radio">
<div>It's a radio choice</div>
<logic:iterate id="predefinedAnswer" property="predefinedAnswers"
name="questions">
<html:radio name="questions" property="answer" value="id"
idName="predefinedAnswer">
<bean:write name="predefinedAnswer" property="label" />
</html:radio>
</logic:iterate>
</logic:equal>
</logic:iterate>
The questionSetForm class defines only one property that hold a
collection of Question instances:
public List getQuestions() {
return questions;
}
public void setQuestions(List questions) {
this.questions = questions;
}
The Question class defines the following relevant properties (along
with corresponding get/set methods):
private Integer id = null;
private Integer questionSetId = null;
private String type = null;
//Holds the collection of the PredefinedAnswer instances
private List predefinedAnswers = null;
private String label = null;
private String answer = null;
The PredefinedAnswer class defines the id and label properties used to
render the list of choices.