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'm new to struts and I'm stuck. I'm reading values on a Form from a jsp page and writing to a different Form on another jsp page. However, I can't access the second Form in my ActionForm class, because only the first form was passed over.
So, how can I get access to other Forms in my Action class?
The execute method of the Action class is provided with an single ActionForm parameter which is the form attribute specified in struts-config.xml for the given Action.
I think you can do something like this,
Create an value object which holds the data received from ActionForm1 i.e PackageForm. Place this value object in the session after calling its corresponding setter methods. In the subsequent action class you can get this value object from the session and populate the ActionForm2 i.e ServiceForm accordingly.
I think this is the best way of doing it.
Joined: Jul 18, 2006
Thanks for the response Ajay.
The problem I'm having is that the execute method in the Action class only passes the PackageForm in the request. In the same action class, I'm going to process the data I receive from PackageForm and set the values in ServiceForm.
However, I'm getting a NULLPointer exception, because the Action class is not aware of the ServiceForm. It only got PackageForm as a parameter.
Does struts have a form dispatch method that you can retrieve different Form beans from the Action class?
My suggestion would be to stop using DynaActionForm. The problem with DynaActionForm is that you can't instantiate it. It can only be instantiated by the Struts framework. If you write a JavaBean that extends ActionForm and specify that as the type in your <form-bean> stanza, you can then instantiate it and put it in the proper scope. Struts will then use it when the second JSP is displayed. Example: