开发者

Struts2: Radiobutton, Iterations and List trouble

I have a complicated problem and I hope to explain it clearly possible...

I have 2 list. On my jsp I have a nested iteration with this 2 lists, inside this there is a tag.

This is the code:

<s:iterator value="listSurveyToRender" var="s" status="counterS">
                 <s:iterator value="listSurveyValuesToRender" var="sv" status="counterSv" >
                          <s:if  test="%{#s.idsurvey==#sv.survey.idsurvey}">
                             <td><s:radio list="sv"  listValue="valoreTesto" name="provaRadio1" />
                          </s:if>
                 </s:iterator>

This is the result of this jsp:

Question 1: (first iterator)
   resp 1:          (second itera开发者_如何学运维tor)
   resp 2:
   resp 3:
Question 2: (first iterator)
   resp 1:          (second iterator)     
   resp 2:

The problem is that, when I select the radio, because the list is unique for all, the selection exclude the others...

I need to restrict this exclusion on the second iterator.

Thanks!


To the point: to separate radio button groups, you need to give them each a different name.

I don't do Struts, but in theory, replacing

name="provaRadio1"

by

name="provaRadio1${counterS.index}"

should do.

Reading/interpreting the generated HTML source (open page in browser, rightclick, view source) should also give a lot of new insights.


It may be possible to do something like this:

  <s:set name="x" value="0"/>
<s:iterator value="listSurveyToRender" id="s" status="counterS">
             <s:set name="x" value="%{x + 1}"/>
             <s:iterator value="listSurveyValuesToRender" id="sv" status="counterSv" >
                      <s:if  test="%{#s.idsurvey==#sv.survey.idsurvey}">
                         <td><s:radio list="sv"  listValue="valoreTesto" name="provaRadio%{x}" />
                      </s:if>
             </s:iterator>
 </s:iterator>

I haven't had a chance to test this but basically every outer iteration will increment x and x will be used to create a unique id for the radio button of each group.

In your action you will have to declare provaRadio1, provaRadio2 etc to get the value submitted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜