dynamic radio buttons using struts logic iterate
Hi,
I have list of questions and list of choices mapped to each question. I want to display the questions and choices in the jsp with choices being radio buttons. I am calling an external service and I am getting response with any number of questions or choices.
I have the created beans for Question and Choice.
Code Strutcure is as follows:
Code:
public class ResponseForm extends ActionForm{
private List questions;
//
public void setQuestions(List questions){
this.questions = questions;
}
public List getQuestions(){
return questions;
}
}
Code:
public class Question{
private List choices;
public void setChoices(List choices){
this.choices = choices;
}
public List getChoices(){
return choices
}
}
Code:
public class ChoiceOption{
private String choiceOption;
public void setChoiceOption(String choiceOption){
this.choiceOption = choiceOpiton;
}
public String setChoiceOption(){
return choiceOpiton;
}
We were able to display the radio buttons in the screen but when selecting the choice we are not sure how to map it back to bean objects
Code:
<logic:iterate name="questionsList" id="data" scope="session" type="check.Question">
<bean:define id="choiceList" name="data" property="choices" ></bean:define><br>
<logic:iterate id="choi" name="choiceList" indexId="j" type="check.Choice" >
<%String choOption = choi.getChoiceOption();
String questionID = "Question"+data.getQuestionID(); %>
<tr>
<td valign="top" align="left" class="urTxtStd">
<bean:define id="choiceID" name="choi" type="check.Choice" ></bean:define>
<input type="radio" name="<%=questionID%>" value="<%=choOption%>" onclick="setSelection('<%=questionID%>');"></input>
<bean:write name="choiceID" property="choiceOption" ignore="true" /> <br>
<td>
</tr>
</logic:iterate>
</logic:iterate>
Please help me on how to map the data with the forms after selecting and submitting
Re: dynamic radio buttons using struts logic iterate
Look around the FAQs of the forum and discover how to post code so that it retains its formatting.
db