File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Reusability of the form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Reusability of the form" Watch "Reusability of the form" New topic

Reusability of the form

Prams Coolkarni

Joined: Nov 01, 2005
Posts: 12
Hi folks I have been developing an appliction in using struts configuration of action and form beans. Now i m using a action class and calling a form bean from it so that using request i can get data which i can display in the JSP. Now i have generated other action class but want to fetch the same data for the display, my question is that can i map a single form with two different action classes? And also after doing so will my first functionality be affected as i will be accessing same form from different classes during same session.

Thanks in advance for giving me some tip or so in this regard.

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You can use the same form bean by any number of actions. This is quite commonly done. Many Struts developers follow a pattern of creating at least 2 actions for every panel: An init action and a process action, both of which use the same form bean.

Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
If you have your action configured to use session scope (the default) then yes there can be side effects of using the same form in different actions. Struts will store your populated form in session and all actions will use this same instance. In this case you have to think about how you want to implement the reset method on your form

As a rule I configure my actions to use request scope. In that case Struts instantiates a new instance of your form with each new request so data is not retained from previous actions. I am a little fuzzy on best practices regarding the reset method since I generally do not have to worry about implementing that method.

- Brent
I agree. Here's the link:
subject: Reusability of the form
jQuery in Action, 3rd edition