----- Original Message ----- From: "Ted Husted" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Sent: Friday, June 20, 2003 6:10 AM Subject: Re: ActionForm 'reset' method being called when JSP is rendered
> 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 guess for new Struts users they should also be aware of the need of resetting array or array list for select menu and multibox, am I right? I have been constantly researching a general algorithm of the resetting properties for the Struts framework, but it is very hard to be *general* even though I got one for our own product. > > 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. > > > -- > Ted Husted, > Struts in Action <http://husted.com/struts/book.html> > > Jing Netspread Carrier at http://www.netspread.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]