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>
When you submit data to Struts the following things happen:
struts-config.xml
passes the request to the appropriate Action class.reset()
is called on the ActionForm. This is where you reset checkbox properties to false. This is needed because unchecked HTML checkboxes are not sent on the request when you submit, so Struts does no request data binding for them (if they were checked when you loaded the page they remain checked even if the user unchecked them on submit);validate()
method is called if so specified in struts-config.xml
;struts-config.xml
(the submitted data is what the page will display because it's on the ActionForm);execute()
method on the Action class is called;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.