1

I have a checkbox inside an iterator, in a JSP page. Whatever I tried, the attribute value of the checkbox tag stay with the 'true' value, even when the value of the field value is the one I want. But I can't get back it. I only get 'true'.

 <s:iterator
    id="pieceJointe"
    value="listePiecesJointesTrouvees">
    <tr height="30">
        <td>
            <s:property value="codeDemande" />
        </td>
        <td
            headers="actions"
            class="center">         
            <s:checkbox 
            value="%{chemin}"
            fieldvalue="%{chemin}"                      
            name="checkbox" /> 
        </td>           
    </tr>
</s:iterator>

The variable chemin getting back with fieldset attribute is the one I want. I can see it with the Web Inspector but I can't take it in the code. I only get back the value of 'value' variable which is desperately "true" value.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • you value is the same as fieldvalue, the reason of using the same value for both fields? – Roman C Feb 19 '16 at 17:04
  • Show your action; meanwhile, read http://stackoverflow.com/a/35064012/1654265 and http://stackoverflow.com/a/21827853/1654265 to get some tips on how the checkbox thing works – Andrea Ligios Feb 19 '16 at 22:48

1 Answers1

0

When using iterator tag to populate a page with input elements like checkbox you can use value attribute to preselect the state of checkbox. The fieldValue is different it's used to set the actual value of the generated HTML checkbox, but s:checkbox tag is a composite tag, along with HTML checkbox tag it also generates a hidden field and set the field value into it. So you don't have to use value and fieldValue with the value from the list.

Again, using iterator tag with the list and a requirement to submit those values. You should use indexed property names. This indexed names are used as parameter's names in the request, and allows to be populated via params interceptor to the list property of the action class.

<s:iterator
    id="pieceJointe"
    value="listePiecesJointesTrouvees" status="status">
    <tr height="30">
        <td>
            <s:property value="codeDemande" />
        </td>
        <td
            headers="actions"
            class="center">         
            <s:checkbox 
            value="%{chemin}"
            name="listePiecesJointesTrouvees[%{#status.index}].chemin" /> 
        </td>           
    </tr>
</s:iterator>  

Make sure you use default stack of interceptors which include checkbox interceptor. This interceptor is required to populate unchecked values.

Roman C
  • 49,761
  • 33
  • 66
  • 176