Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2: Dynamically returning to last page shown after an action call from a form submit.

 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a collection of pages in a site that hold the same user login form, just 2 fields.

They all call a login method on the same action class but what I would like to do is return to the page where the submit came from.

Is this possible?

Thanks,

 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

First of all define one global variable

private String action;

make getter and setter method for your action variable.

then use
<s:form name=%{action} method="post" >


</s:form>

 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nishan,

I am not sure how that would work.

the form is on many pages but goes to the same action class.

<s:form action="user!login" >
.....<s:textfield name="user.username" size="10" label="username"/>
.....<s:password name="user.password" size="10" label="password"/>
.....<s:submit value="login"/>
</s:form>

Here is my action mapping

<action name="user" class="com.forum.web.UserAction" method="input" >
...<result name="success" >index.jsp</result>
</action>

And as you can see it always goes back to index.jsp but really I want it to go back to the page where the form was displayed ( the same page where the person was on before they used the login form ) and there are many JSPs where this form is displayed

Now I know that you can use a dynamic forward, so if I create a variable fromPage in my UserAction I can then make my action mapping..

<action name="user" class="com.forum.web.UserAction" method="input" >
...<result name="success" >%{fromPage }</result>
</action>

But it is populating that variable with the Action that I use to to create the jsp which shows the login form. I can easily pass in the JSP path in a hidden variable but all JSPs are created after an Action class call.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic