Hi, ppl i want to make a checkbox checked on page load, i want to do this in <html:checkbox /> whereas there is no such reference to setting this value as was in the case of <checkbox checked>. And if the user unchecks the checkbox it should be uncheked and the value to be saved to DB should be 0.
What Nathan meant was that JUST BEFORE you enter the page for the first time, you'll want to call the setter on the field that corresponds to the checkbox so the checkbox will be checked when you first enter the page. Usually this is done from an Action, and often so from a SetupAction which will involve minor Action chaining.
Originally posted by Vani D Bandargal: Initialize your form bean property with the value to be passed on checking Check Box
Good idea, but that won't work completely. Following that method, if a user were to deselect the checkbox, the value in the ActionForm will never reflect it because empty checkboxes don't get submitted as a parameter.
Joined: Oct 06, 2005
Thank you Marc for your feedBack. We can always overide the reset method of ActionForm to avoid any problems with the check boxes.
I am using similar kind of technique in my current project. Let me know if my undestanding is not correct
The problem with that is the reset method gets called after the form gets created. If reset is "unchecking" the value and you are not "rechecking" the value in a Setup Action, the value would be unchecked when you enter the page.
The reset method generally also has no merit unless you are setting your ActionForms to session scope, as it was created to solve "the checkbox problem" for forms in session scope.
I'm surprised that you say you are using it in your project and that you say it works.
Hi, sorry to reply to older post, this was a problem for me tongight.
Not sure how applicable it is to other implementations, but here is what I did to get this to work.
my form has boolean property tabbedView, that is rendered with a checkbox on the html form, that i wanted to be default checked. (but it was not working for me)
So, the JSP has <html:checkbox property="tabbedView"> for the check box, and the <html:hidden property="formAction" value=""/>
The formAction is then available on the request parameters if the form has been submitted, and unlike checkboxes, it is always available.
Then the reset() in the ActionForm:
So the reset does not clear default checkbox value before it should, but maintains the current state of the checkbox when the form is submitted. (happiness).
I guess you could use have the if() statement in the reset() look for some other property is always available when the form is posted, and is unieuq to this particular form. One thing to note, as was happening to me, if the formAction hidden property is ALSO available on the previous screen that forwarded to this screen with the default true checkbox, there would be a request parameter present for the formAction, and the feature degenerates to as it was before, where default true property always gets unsolved. (be set in advance, and the reset() would clear it). In this case, you can either use different (unique to this form) name to inspect for, or use redirects between your forms (if you can use a redirect instead of a forward).
Error: Keyboard not attached. Press F1 to continue.