This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes several actions with same action class and only one instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "several actions with same action class and only one instance" Watch "several actions with same action class and only one instance" New topic

several actions with same action class and only one instance

Jonas Eichhorst

Joined: Nov 22, 2010
Posts: 1
Hi all,

I have 4 forms which together compose an entity-adding action (each part is validated differently and individually, therefore, they are split). Now I have set up everything so that I go from tile to tile via the action and everything seems to work well so far.

However, each of the actions points to the same class and the information (instance variables) are always only passed from the one step to the next but then lost when the following form is loaded.

My struts.xml looks like this:

And basically everything seems to be almost great, only problem is that the steps should be:

And the information in the instance of de.nak.stundenplandb.action.EditVeranstaltungsreihenlisteAction (if I look via Debug) is only passed from 1 to 2, then in 2 some stuff is added and then when I move to form three the settings from form one are lost.

Any ideas how I can ensure that all these actions use the same instance of de.nak.stundenplandb.action.EditVeranstaltungsreihenlisteAction?

Thank you very much in advance!
Joe Ess

Joined: Oct 29, 2001
Posts: 8836

Are you using Struts 1 or Struts 2? Looks like Struts 2.
In any case, using instance variables is a Very Bad Idea. In Struts 1, there's only one instance of an action created so instance variables will cause race conditions. In Struts 2, a new instance of an Action is created with each request, so you'll lose the instance variable values.
I would us a user session to store the values you want to carry along the process.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: several actions with same action class and only one instance
Similar Threads
Struts 2: Forms with multiple submit buttons - Best Practice?
scope prototype not being thread-safe
how to know if has validation errors on jsp
Struts & Tiles frame work issue
Passed SCBCD