Hi Hope that any one can help me on this problem: when the selected check boxes do not pass the edits, I return the same page with error message but the boxes user checked before submitting are unchecked.
What do I need to do to tell Strut to repopulate the check boxes? Thanks
I have three check boxes coded in JSP as follows: <html:checkbox property="checkedAction" value="printerCopyCCChecked" title="Print Copy in CC" /><b>Print Copy in CC</b <html:checkbox property="checkedAction" value="modifyClmtCopyChecked" title="Modify & Reprint Claimant Copy" /><b>Modify & Reprint Claimant Copy</b <html:checkbox property="checkedAction" value="reprintClmtCopyChecked" title="Reprint Claimant Copy" /><b>Reprint Claimant Copy</b and My Action Form has: private String  checkedAction; to store the value when user checks the check boxes. [ October 02, 2007: Message edited by: Quang Pham ]
When you have a set of checkboxes all with the same property name, you should use html:multibox instead of html:checkbox. If you do so, Struts will cause the boxes to show as checked or unchecked based on the value of the ActionForm property.
You are right. But our users want check boxes. Another question: How do I get Struts to call the reset method every time user click submit button? If I can do this, simply my problem is resolved. *** Currently I only able to call reset method only one at the time the Action Form constructor is invoked. *** At first, I create different name for each check box. But Struts do not reset the Action Form check box field if I unchecked the box. When the box is checked, it stays checked due to Struts by pass calling set method for those unchecked boxes. Later I use the same name for all check boxes. It solve the problem I got above but struts unchecked all the check boxes when return back to JSP. It is not appropriate to tell user "Invalid combination selection" with all check boxes are uncheked. Thanks for your help [ September 28, 2007: Message edited by: Quang Pham ]
Originally posted by Quang Pham: You are right. But our users want check boxes.
Both html:checkbox and html:multibox produce a checkbox. There is absolutely no difference in the way they appear on the screen. The only difference is behind the scenes in the way that Struts decides which box should appear checked and which unchecked.
Originally posted by Quang Pham: How do I get Struts to call the reset method every time user click submit button?
You don't have to do anything. This is the Struts default behavior. Whenever the form is submitted, the reset method is called prior to populating the properties of the bean with its setter methods.
The problem you're experiencing has to do with the way HTML works with checkboxes. When it is unchecked, HTML does not submit any value when the form is submitted. To work around this, you have to put code in your reset method that will reset any values associated with the checkbox. In your example, you should put the following code in your reset method:
[ September 28, 2007: Message edited by: Merrill Higginson ]
Merrill Not quite solve the problem. After check all boxes and submit, Struts does remember to populate the checked boxes. But then when I unchecked all of them, Struts bypass the set method and come back put the check on the selected boxes I submit the first time. Struts does not unchecked the boxes if all of them are unchecked. Any idea? Quang
This is the point I was trying to make in the second part of my previous post. HTML does not submit any value to the server if a box is unchecked, which means that your ActionForm's setter will not be called. The work around is to place the line
in your ActionForm's reset method. Also, make sure the method has the correct signature as defined in the JavaDoc.
I have the check boxes field in reset method but the reset method never been called every time the submit button is pressed. The debugger never stop there. I think it may have some thing to do with the supper class my action form extends to. My action form class extends to our company ActionForm supper class which in turn extends to org.apache.struts.action.ActionForm; Let me check with the frame work guy to see if the problem is in the supper class. It's a good learning today. Thank you again Quang
It is populating correctly. And also when submitting the page I'm getting the values of selected locations in a array 'locationList'
when i want to update my records in database, I want to populate my records in the page. for example, If i have more than one location for the record, I fetch those locations, and put it in 'locationList' property in my form.
But i dont know how to populate these locations with selected checkboxes. in my Page i'm having 'locationsList' having all the locations.it is a collection. 'locationList' having the location names to be selected. it is form bean property.it is ArrayList.
from these two collections, how can I populate my checkboxes with the selected locations?