Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Struts and the fly likes how can I make two actions communicate with each other Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how can I make two actions communicate with each other" Watch "how can I make two actions communicate with each other" New topic
Author

how can I make two actions communicate with each other

amit gupta
Greenhorn

Joined: Dec 29, 2006
Posts: 23
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

SCJP 1.5, SCWCD 5.0
rogel garcia
Ranch Hand

Joined: Dec 19, 2003
Posts: 41
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?


SCJP 1.4
amit gupta
Greenhorn

Joined: Dec 29, 2006
Posts: 23
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 15, 2008
Posts: 93
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

Joined: Dec 19, 2003
Posts: 41
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

Joined: Dec 29, 2006
Posts: 23
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

Joined: Dec 19, 2003
Posts: 41
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

Joined: Dec 29, 2006
Posts: 23
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

Joined: Dec 19, 2003
Posts: 41
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

Joined: Sep 29, 2008
Posts: 12617

${result}

use EL.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how can I make two actions communicate with each other
 
Similar Threads
action chaining
How to do Action mapping for this scenario ??
forwarding request to an action from a jsp page
Action called/used by multiple jsps
How to "carry" JSP form input over few pages (clicks) down ?