• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Form beans values transferred to another form bean

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Rajani Deshpande
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rajani Deshpande
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic