Hi, I have 2 form beans in request scope. Say formbean A and formBean B. I have delete and new buttons in both the jsps and so I have identical getter/setter methods in both beans. When Action Form A is called on delete, the delete variable is not null. It performs the delete and forwards it to actionform B. The reset methods are being called...( I can see that in the debug mode)... But once it comes to actionForm B, it still has some value in the delete variable and so it again tries to delete which is not the behaviour I am expecting.... I am doing almost the same logic with the new button and that works fine. I am not able to understand why one form beans values are retained in another form bean? Hope there is some sensible answer to this....
You have to be careful when forwarding from one Action directly to another Action. When you forward to the second Action, the Struts processing cycle is repeated. That is, the framework calls the second ActionForm's reset(), then populates it's fields from the request parameter values, then calls the execute() method. Since you're processing the same request, the parameter values are still in scope and the values that were originally submitted are pushed into the second form's fields.
Yes, this is exactly what is happening. but I thought the form values are tied to the form bean, so even though the second form bean has some fields same as the first bean, it is a new different bean and so I would expect all the value parameters to be reset. So how do I get around this problem? I dont want to name all my variables differently in both forms.
Why do you need to forward to another Action? I think you need to refactor a bit. Try moving the "business logic" from the second action to a "helper" class and invoke the helper class instead. That is, both Action1 and Action2 will delegate work to the helper class instead of Action1 passing control on to Action2. As for the data you need, try applying the Data Transfer Object pattern. See this tutorial for some good examples of application layering and separation of responsibilities.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Form beans values transferred to another form bean