If you have an ActionForm associated with the form's Action, and if you use either the Struts <html:checkbox> or <html:multibox> tags, Struts will do this for you automatically. It will cause the box to be either checked or unchecked based on the value of the ActionForm property you specify.
If the above is true for your form and it's still not working, post your code (relevant portions of the JSP, ActionForm, Action, struts-config.xml file, etc.) and we'll help you debug it.
Thanks for your response Merrill. Let me verify this and get back to you.
Thanks again! Kunal
Joined: Apr 08, 2005
I am using the html checkbox in the jsp. The following are the code snippets
The physicianForm is specified as follows:
In the reset method of the NewBusinessDynaValidatorForm, I reset the checkbox
Could someone point me in the right direction.
Joined: Feb 15, 2005
It appears to be the code in your reset method that is the problem. It should set the value of "hasPhysician" to false, not true. The reason for this is a quirky behavior of HTML. When a checkbox is checked, HTML sends a parameter to the server with the appropriate name and value. However, when the box is not checked, HTML does not send anything to the server. It's therefore important that your reset method set the value of the property to the value you want it to have if the box is not checked, which in this case is false. That way, if the box is not checked and nothing is sent to the server, it will still have the correct value. If the box is checked and a value is sent to the server, it will override what is set in the reset() method.
If you want to set an initial value of true when the page is first displayed, do so either with by specifying initial="true" in the <form-property> tag in struts-config.xml, or by setting the property to true in the Action class that first forwards to this JSP. [ February 13, 2007: Message edited by: Merrill Higginson ]
Joined: Apr 08, 2005
Thanks for your response Merrill! I was finally able to retain the value of the checkbox.
We are using a datamodel and I used the model to store the value of the checkbox and I retrieved it from the same place.