• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 9707
43
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?
 
I've never won anything before. Not even a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic