This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Action Class member variables in Session Struts2

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Sheriff
Posts: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please make sure to UseCodeTags when posting code or configurations.

As previously stated: actions are instantiated per-request.
 
Prav Chau
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the solution is to put the object in session?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic