struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Husted <>
Subject Re: ActionForm 'reset' method being called when JSP is rendered
Date Fri, 20 Jun 2003 11:10:28 GMT
Jerry Jalenak wrote:
> The doStartTag has a call to initFormBean; in initFormBean there is a call
> to RequestUtils.createActionForm, followed by a call to the ActionForms
> 'reset' method.  In a wizard type of application, this could indeed cause
> problems where the reset method may be clearing values from the ActionForm;
> I've had to add code to a couple of my projects to check the mapping to see
> if I wanted to reset or not.  Maybe one of the guru's could shed some light
> on why the <html:form/> tag would instantiate the ActionForm and call reset
> when the JSP is rendered, opposed to doing this when the form is actually
> submitted....

In the normal course, the ActionForm is instantiated by the controller, 
and reset is called before autopopulation. Some people use reset for 
things aside from clearing fields, and so reset is also called if the h 
html:form tag needs to instatiate the form.

The mistake most people make is resetting properties needlessly. 
Generally, the one and only property that needs to be cleared by reset 
is a checkbox in session scope. This is simply because an unchecked box 
is not submitted. If the bean is in session scope, there is no way to 
turn it off again, and without reset, it remains forever true.

I would hazard to say that the best practice should be to use code like 
this in your reset method

if ((SESSION.equals(mapping.getScope())) setMyCheckbox(false);

and to never clear any other property without a specific cause.


Ted Husted,
Struts in Action <>

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message