Subject: Re: problem with nested tag and resetting checkboxes From: "Jeff" <[EMAIL PROTECTED]> === Does ActionForm have an abstract method that gets called AFTER a form submission, but BEFORE the submitted formvars are used to (re)populate the associated ActionForm bean's values? reset() doesn't seem to be the answer.
Attempting to set the bean's values to the un-checked default in the reset() method isn't working, because reset() isn't getting called until AFTER the bean's values have already been populated with the form's values. The problem is, by that point, it's too late to reset the boolean variable corresponding to the checkbox, because setValue(checkbox value) has (possibly) been called already... but without doing anything extra, we can't be sure whether it was or wasn't. I've come up with a really ugly kludge that works (below), but I can't believe there isn't a better solution within Struts itself to handle the scenario of checkboxes whose absence should be interpreted as "false" rather than "ignored" The kludge: assume the checkbox corresponds to a boolean variable named "good", with the usual get()/set() methods. add two boolean variables to the bean: unchecked_default and box_was_checked. unchecked_default has the usual get() and set() methods. box_was_checked is for internal use and is initially set to "false" a hidden form tag is added that specifies the default value to use if the box isn't checked: <nested:hidden property="unchecked_default" value="false"/> setGood(boolean) -- the set method for the variable associated with the checkbox -- sets box_was_checked=true whenever it gets called setUnchecked_default(String) -- the set method for the hidden formvar that contains our "unchecked" value -- checks to see whether box_was_checked == true. If box_was_checked = true, it sets box_was_checked = false and does nothing further. If box_was_checked = false, it directly sets good = (Boolean.valueOf(String)).booleanValue() The general idea is that the checkbox's corresponding value gets set to the default if the formvar is missing from the submission (indicating that it was unchecked, and thus ignored). On the other hand, if it WAS submitted, but some random quirk of luck caused setUnchecked_default() to get called before setGood(), everything will still work out, because the default value will get overwritten before perform() gets called. So, anyway, is there some better way to do this? Does Struts have some built-in mechanism for automatically setting checkbox properties to some default value prior to processing the submitted formvars? Perhaps the <html:checkbox> (and <nested:checkbox>) tags should have an additional parameter -- "unchecked_default", whose use would cause Struts to silently insert an additional hidden tag into the page to more or less achieve the same result as my kludge? -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>