Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing variable parameters in action class (Radio element), struts 2
    text
    copied!<p>I'm developing a Multiple Choice Quiz Application using <code>struts2</code>. The admin can decide how many questions the test will contain. So now my action class that'll receive the answers will have to receive multiple and unknown parameters.</p> <p>Question are printed using iterator, Options are also randomized using a list named "randomNos" which contains random number.</p> <pre><code>&lt;%int i=1; %&gt; &lt;s:iterator var="i" value="quesList"&gt; &lt;input type="hidden" value="&lt;s:property value="QuesId"/&gt;" name="quesId"/&gt;&lt;%=i++ %&gt;) &lt;s:property value="Ques"/&gt; &lt;s:iterator var="j" value="randomNos"&gt; &lt;s:if test="intValue() == 1"&gt;&lt;input type="radio" name="ans" value="1"&gt;&lt;s:property value="[1].Ans1"/&gt; &lt;/s:if&gt; &lt;s:elseif test="intValue() == 2"&gt;input type="radio" name="ans" value="2"&gt;&lt;s:property value="[1].Ans2"/&gt; &lt;/s:elseif&gt; &lt;s:elseif test="intValue() == 3"&gt; &lt;input type="radio" name="ans" value="3"&gt;&lt;s:property value="[1].Ans3"/&gt; &lt;/s:elseif&gt; &lt;s:else&gt; &lt;input type="radio" name="ans" value="4"&gt;&lt;s:property value="[1].Ans4"/&gt; &lt;/s:else&gt; &lt;/s:iterator&gt; &lt;/s:iterator&gt; </code></pre> <p>Now to receive the parameter I tried "<a href="https://stackoverflow.com/questions/10900605/passing-variable-number-of-parameters-from-form-in-to-action-in-struts-2">Passing variable number of parameters from form in to action in struts 2</a>" But in my case I have Radio buttons, so now only one question's radio is selected as all buttons have the same name.</p> <p>In my action I have</p> <pre><code>List&lt;String&gt; quesId; List&lt;String&gt; ans; </code></pre> <p>and I iterate over both lists using iterators.</p> <p>But the problem is only one option is selected of all questions. If I use a different "name" of the radio tags, I can't manage to put them in a list. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload