You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Don Jones <do...@kdsi.net> on 2000/10/04 21:39:06 UTC

ActionForm clearing

When using a <struts:submit>  do I need to manually clear the ActionForm
or is there some built-in STRUTS functionality that will do this for
me?   It is probably right in front of me and I am not seeing it.   In
my app, after a <struts:submit> I forward back to the jsp from which
this form can be selected again.  When selected the inputs from the
previous entry are still in the form.

Cheers,
Don Jones



Re: ActionForm clearing

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Yun Sang Jung wrote:

>
>
> [Image]
> >
> > Here's how I normally handle this scenario.  In the Action class that
> > handles this form submit:
> > * Perform whatever task is requested
> > * Remove the form bean session attribute
> > * Forward to whatever JSP page is appropriate.
> >
> > When the  tag of the form sees that there is no form bean
> > there, it will create a new one (with whatever default values you have
> > defined in the class itself) and store it in the session.  From the user's
> > perspective, that's a new blank form.
> >
> > In general, it is a good practice to delete form beans from the session when
> > you are through with them -- otherwise they just sit there occupying memory
> > until the session is invalidated or timed out.
>
> Did you mean I should call
> "session.removeAttribute(mapping.getFormAttribute()); "?
>

Yes, that is exactly the kind of thing you can do when you no longer
need the form bean.  If this was the only reference to that bean (which
is the normal case), it will now be available for garbage collection.

Craig

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat


Re: ActionForm clearing

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Don Jones wrote:

> When using a <struts:submit>  do I need to manually clear the ActionForm
> or is there some built-in STRUTS functionality that will do this for
> me?   It is probably right in front of me and I am not seeing it.   In
> my app, after a <struts:submit> I forward back to the jsp from which
> this form can be selected again.  When selected the inputs from the
> previous entry are still in the form.

Here's how I normally handle this scenario.  In the Action class that
handles this form submit:
* Perform whatever task is requested
* Remove the form bean session attribute
* Forward to whatever JSP page is appropriate.

When the <struts:form> tag of the form sees that there is no form bean
there, it will create a new one (with whatever default values you have
defined in the class itself) and store it in the session.  From the user's
perspective, that's a new blank form.

In general, it is a good practice to delete form beans from the session when
you are through with them -- otherwise they just sit there occupying memory
until the session is invalidated or timed out.

>
> Cheers,
> Don Jones

Craig McClanahan

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat