Results 1 to 2 of 2
  1. #1
    shariprasad83 is offline Member
    Join Date
    Apr 2012
    Rep Power

    Default dynamic radio buttons using struts logic iterate


    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:

    Java Code:
    public class ResponseForm extends ActionForm{
    private List questions;
    public void setQuestions(List questions){
    	this.questions = questions;
    public List getQuestions(){
    	return questions;
    Java Code:
    public class Question{
    private List choices;
    public void setChoices(List choices){
    	this.choices = choices;
    public List getChoices(){
    	return choices
    Java 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

    JavaScript 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(); %>	
    		<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>																			
    Please help me on how to map the data with the forms after selecting and submitting
    Last edited by shariprasad83; 04-07-2012 at 09:45 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default 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.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Help buttons
    By 10e5x in forum New To Java
    Replies: 3
    Last Post: 01-04-2011, 08:10 PM
  2. Replies: 0
    Last Post: 07-13-2010, 06:25 PM
  3. problem with <logic:iterate> tag looping
    By tsaswathy in forum Web Frameworks
    Replies: 0
    Last Post: 09-27-2008, 12:13 PM
  4. How to use Radio Buttons
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 02:26 PM
  5. iterate HashMap with logic
    By Heather in forum Web Frameworks
    Replies: 2
    Last Post: 07-03-2007, 09:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts