aspose file tools*
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
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
Author

several actions with same action class and only one instance

Jonas Eichhorst
Greenhorn

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:
1.EditVeranstaltungsreiheStammdaten
2.EditVeranstaltungsreiheDozent
3.EditVeranstaltungsreiheGruppe
4.EditVeranstaltungsreiheRaeume

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
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

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]
 
Consider Paul's rocket mass heater.
 
subject: several actions with same action class and only one instance