• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can I make two actions communicate with each other

 
amit gupta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

The problem is like :

1) jsp 1 calls jsp 2 for some calculation.
2) jsp 2 calls action2 and does all the processing and mapping.findforward("jsp1"), will redirect to jsp1.
3) now, action1 should continue its working with the values returned by action2.

suppose these values are totalAmount and totalDistance;

I am not able to get totalAmount and totalDistance in action1.

I have taken the same variable names in form1 and form2 as totalDistance and totalAmount and provided the getters and setters in both forms.

could anyone give idea why these variables are not giving any value in action1. they are assigned proper values in action 2.


Please suggest.

Thanks in advance
 
rogel garcia
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there something wrong with this?

1) jsp 1 calls jsp 2 for some calculation.
2) jsp 2 calls action2 and does all the processing and mapping.findforward("jsp1"), will redirect to jsp1.
3) now, action1 should continue its working with the values returned by action2.


Where action1 is called?
 
amit gupta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rogel garcia wrote:Is there something wrong with this?

1) jsp 1 calls jsp 2 for some calculation.
2) jsp 2 calls action2 and does all the processing and mapping.findforward("jsp1"), will redirect to jsp1.
3) now, action1 should continue its working with the values returned by action2.


Where action1 is called?



my apologies for not being clear .

jsp1 -> action1, on click of a button on jsp 1, jsp 2 is called and then action 2.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean action 1 should "continue" with values from action 2? There is no "continue": it's a new request.
 
Nevin kumar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use type=chain to navigate from one action to another in struts2

example :
<action name="makerDetails" class="abcAction">
<result name="redirect-abc" type="chain">
<param name="actionName">venus</param>
<param name="namespace">/wm</param>
</result>
</action>
 
rogel garcia
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Action1 -> JSP1 ... then onclick -> Action2 -> JSP2?? Correct?

And you want that Action1 execute something based on what Action2 has calculated?

Or from Action2 do you want to dispatch to Action1 again?


Like David asked:
What do you mean action 1 should "continue" with values from action 2?

 
amit gupta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rogel garcia wrote:Action1 -> JSP1 ... then onclick -> Action2 -> JSP2?? Correct?

And you want that Action1 execute something based on what Action2 has calculated?

Or from Action2 do you want to dispatch to Action1 again?


Like David asked:
What do you mean action 1 should "continue" with values from action 2?




I want Action1 execute something based on what Action2 has calculated, after Action2 has dispatched to action1.

basically , these are two different requests , as mentioned above.

the problem is I am not able to use the resulting values of Action 2 in Action1.

I hope this clarify the problem.



 
rogel garcia
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
putting some attributes in the session does not solve the problem??

In Action2:

request.getSession().setAttribute("myvalue", xyz);


In Action1:

Object xyz = request.getSession().getAttribute("myvalue");

??
 
amit gupta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:What do you mean action 1 should "continue" with values from action 2? There is no "continue": it's a new request.


David,

I meant

1) jsp1->action1->(executes search)->(some search values are displayed on jsp1)->
2) jsp1(using javascript on click of a button )->jsp2() ->Action 2(perform something and gives "result")->forwarded to jsp1 using mapping.findforward().


now the "result" is not accessible on form1/action1/jsp1

is there any way I can access the values available on action2 directly from action1.

in jsp1 if I use , it shows the value of "result" properly.

But I dont want to use scriptlet in jsp.

Please suggesst.

Thanks
 
rogel garcia
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to set an attribute...

A request one will be enought


In action2:

request.setAttribute("result", mylist);


In JSP1:

${result}
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${result}

use EL.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic