aspose file tools*
The moose likes Struts and the fly likes Form beans values transferred to another form bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Form beans values transferred to another form bean" Watch "Form beans values transferred to another form bean" New topic
Author

Form beans values transferred to another form bean

Rajani Deshpande
Ranch Hand

Joined: May 08, 2000
Posts: 45
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....
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
coz u are not doing anything in the reset method and by the way why do u have the 2 form beans for 2 jsps?


Adios
Rajani Deshpande
Ranch Hand

Joined: May 08, 2000
Posts: 45
Of course, I am resetting the values in the reset method. If I use different variable names , it works fine. I dont know why the values of one bean are transferred to another bean!
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5288
    
  10

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.


Junilu - [How to Ask Questions] [How to Answer Questions]
Rajani Deshpande
Ranch Hand

Joined: May 08, 2000
Posts: 45
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.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5288
    
  10

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Form beans values transferred to another form bean