This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have 2 actions. ActionA => prepares data for rendering ActionB => performs action the user selects in jsp.
Both ActionA & ActionB shares same ActionForm.
The process is like this
ActionA => prepares data => forwards to A.jsp => user Clicks on some button which posts to ActionB => ActionB updates/deletes db adds success/failure message to ActionForm & forwards to ActionA => ActionA prepares the data again => forards to A.jsp
Now in A.jsp i check for message set by ActionB, but i cannot find it.....
Not sure why as they share the same form........
Is their any way to share data using actionforms between 2 actions.. if so why is it not working?
Action chaining is not recommended by the Struts authors. Here is a link that will give you more information about it. Below is a quote from this link.
As a rule, chaining Actions is not recommended. If your business classes are properly factored, you should be able to call whatever methods you need from any Action, without splicing them together into a cybernetic Rube Goldberg device.
If you must chain Actions, be aware of the following: calling the second Action from the first Action has the same effect as calling the second Action from scratch. If both of your Actions change the properties of a formbean, the changes made by the first Action will be lost because Struts calls the reset() method on the formbean when the second Action is called.
The approach I'd recommend would be to refactor your classes such that there is a prepareA() method in some class other than an Action class, such as a utility class or a Business Delegate class. This method would do all the work necessary to prepare for the display of A.jsp. Then have both ActionA and ActionB call this method. ActionB would then forward to A.jsp rather than forwarding to ActionA.do.
A common pattern that is not truly "action chaining" is to have ActionB redirect back to ActionA (using a foward with redirect="true" set). You have to keep in mind is that this causes a new request to be created, so any values submitted from A.jsp or set in ActionB will be lost. You can either add parameters to the url or save attributes in the session.