strutsjsp-tagsstruts-validationstruts-html

html-el:checkbox gets checked after a Struts validation error display


I have a very simple issue. Below is my JSP code , where I display multiple check boxes in rows. By default all checkbox are checked, and if user wants to ignore certain row, he unchecks that row's checkbox.

My issue is, if a row's checkbox is unchecked and because of some other fields, if Struts throws a form validation error on screen, the unselected checkbox is displaying back as checked. Am I missing something? If no struts validtion, then everything looks correct.

<c:forEach var="map" items="${form.displayList}" varStatus="index"> 
    <html-el:checkbox styleId="someCheckbox_${index.index}" property="someCheckboxes[${index.index}]"  />
     <td> .....</td>
     <td> .....</td>
     <td> .....</td>
</c:forEach>

Solution

  • When you submit data to Struts the following things happen:

    Is this how you are using Struts? My guess is you are doing some populating/resetting/validations in the Action class and when validation fails you reload the ActionForm with the default data.

    Check your ActionForm for the reset() and validate() code and your Action class for execute() and see where the data is getting checked back.