aspose file tools
The moose likes Struts and the fly likes Action Class member variables in Session Struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "Action Class member variables in Session Struts2" Watch "Action Class member variables in Session Struts2" New topic
Author

Action Class member variables in Session Struts2

Prav Chau
Ranch Hand

Joined: Jul 17, 2007
Posts: 58
Hi,

How do I mention scope for action class? I want put all the member variables for the particular myaction class into session.

Basically I am loosing all the values in the form if struts validation fails. Can someone help me to retain the form values if validation fails in struts2.


Thanks,


Prav Chau
SCJP, SCWCD, SCBCD, SCEA, http://pravinchaudhari.blogspot.com/
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

When validation fails, usually you are sent to the input page which is the page where you submitted the form. The values entered by the user are automatically filled in their respective fields. You don't need to do anything for that. Can you show us the code of your Action and input page...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And the configuration for the action(s) involved. The previous answer pretty much sums it up, though: if you redirect after the submit the form values will be lost. Actions are instantiated per-request.
Prav Chau
Ranch Hand

Joined: Jul 17, 2007
Posts: 58
Action Mapping File: dealer_branchedit action populates the fields on edit page. when I try to save it calles "dealer_branchsave" action.

When validation fails it brings the edit page without existing values. All Drop down values and display only values are lost.

<action name="dealer_branchedit" method="branchedit" class="com.smartequip.vendorportal.action.DealerAction">
<interceptor-ref name="defaultStack"/>
<result name="input" type="dispatcher">jsps/edit_dealer_branches.jsp</result>
<result name="error">jsps/error.jsp</result>
<result name="branchedit" type="dispatcher" >jsps/edit_dealer_branches.jsp</result>
</action>

<action name="dealer_branchsave" method="branchsave" class="com.smartequip.vendorportal.action.DealerAction">
<interceptor-ref name="defaultStack"/>
<result name="input" type="dispatcher">jsps/edit_dealer_branches.jsp</result>
<result name="error">jsps/error.jsp</result>
<result name="branchedit" type="dispatcher" >jsps/edit_dealer_branches.jsp</result>
</action>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please make sure to UseCodeTags when posting code or configurations.

As previously stated: actions are instantiated per-request.
Prav Chau
Ranch Hand

Joined: Jul 17, 2007
Posts: 58
So the solution is to put the object in session?
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Action Class member variables in Session Struts2
 
Similar Threads
Struts2 - Conditional validation
Struts2 - Not forwarding to another action using type="Dispatcher"
Struts2 wizard with scoped model driven
validation in struts2
struts2 validation with conditions!