Reset for validation

Ted Husted

There is a reset() method on ActionForm that is called *before* Struts does the auto-populate trick. The contract is that this method should reset all relevant attributes for this particular form to default values. For checkboxes, you would want to set the corresponding boolean to false. It will be set to true by the auto-populate method *if and only if* the checkbox was checked (and therefore included in the POST).

For integers, it is technically feasible to distinguish an empty field ("") versus a zero ("0"). If we decide not to call the setter in this scenario, then the ActionForm property will remain at it's default value, so you can distinguish whether it was entered or not.

On the other hand, we could take the approach that the form should have displayed the default value in the first place, and the user would have had to erase the existing value to cause an empty string to be posted -- and that the bean should want to know about that. Because we have to generate a legal integer value, the decision is what value to use for indicating "no input". Zero is the current mechanism for this, but it's not the only choice.