Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Forwarding to another action with parameter

 
Dan Gun
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to forward to another action which requires parameter(s)?

TIA.

For example:

 
Shankar Narayana
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am also trying the same, but coudn't work out yet, when I try to forward to a Action with more than one queryString parameter, it just displays to me that the page cannot be found.

Any ideas
 
Roel De Nijs
Sheriff
Posts: 10400
133
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i did something like this:



hope this helps
 
Prasanna Puttappa
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using setPath() method of ActionForward class. ActionForward inherits this method from ForwardConfig class.

Hope this will be helpful.

-Prasanna
--------------
 
Junilu Lacar
Bartender
Posts: 7595
53
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should always take care when forwarding from one action to another. The most common "bug" that arises from doing this is that of disappearing or overwritten form values (note the quotes). This is not actually a bug but normal behavior. You just need to understand what the framework is doing.

In the case of wanting to pass parameters when forwarding from one Action to another, my experience has been that this is usually a code smell. Code smells should result in refactoring to eliminate the code smell.

But first, why do you need to pass parameters to the second Action? Are the parameter values already in the ActionForm that Action 1 received with the current request? If that is the case, you don't need to do anything since the parameters are already in the request. Just make sure that the ActionForm associated with Action 2 has corresponding fields that will receive those parameters.

If the parameter values were not submitted with the request, I would say refactor and extract the code in Action 2 that uses the parameters. Put that code into a Helper class instead. Then you can use the Helper class from both Action 1 and Action 2 without having to go through the error-prone exercise of forwarding from one Action to another.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic