Web tier: servlets, JSP, Web frameworks: Action Form Scope in Struts
- Posted by: Abraham Mazumder
- Posted on: December 18 2003 14:19 EST
I have read that an ActionForm can be programmed to different scopes - request or session.
But the struts-config.dtd does not mention the form-bean having a "scope" attribute.
Where can the form be scoped then?
Thanks for your time,
- Action Form Scope in Struts by Hari Lakshmanan on December 18 2003 16:40 EST
- Action Form Scope in Struts by mohit srivastava on August 16 2011 15:50 EDT
> I have read that an ActionForm can be programmed to different scopes - request or session.
> But the struts-config.dtd does not mention the form-bean having a "scope" attribute.
> Where can the form be scoped then?
> Thanks for your time,
Normally formbean is associated with the Action and Action element has an attribute "scope" where the scope of the ActionForm is specified. Look under action element in the dtd file for more info.
You can use the same action form for many actions and specify the scope for each action as it is needed.
Many developers associate ActionForm classes (form beans) to a single action when they are instead very reusable classes. That is why the scope is not identified in the <form-bean> tag but instead in the <action> tag where it will be used.
As I understand it the best practice is to limit the amount of information you store in the session scope this doesn't always get cleared out and can effect performance.
1. Is there a pattern that allows you to define your own scope - between session and request which will be cleared out at a specified point?
2. When you are gathering information on a number of pages should you use one big formbean on a number of small ones?
There is no other area other than session request or application you can write data. For your problem you can write a crown job which can check if there is any thing you want to remove you can. Set a timeout at which the data will be cleaned. The crown job will delete the session objects when timeout reaches.
You can always give request scope to your form bean in struts-config file when you map the action . In fact its a good practice and makes the session lighter