This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reusability of the form

 
Prams Coolkarni
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Prams
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brent Sterling
Ranch Hand
Posts: 948
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic