This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem with having identical field names across form beans

 
Ranch Hand
Posts: 376
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have multiple forms, most of which carry address fields like street name, city, state, zip etc. Earlier, we used to name the fields uniquely like UserStreetName, VendorStreetName etc. Then it was decided that the names should be identical across all forms (just "streetName"), because after all, they were in different forms. (we use DynaValidatorForms). This did ease up various processing, like the usage of Tags etc.

We also decided to use DispatchActions, with each Action class having its own display(), submit(), back() methods. Now, we find that the first form displays alright, but the second form holds onto the data from the first form. So, when we reach the Vendor page, it is already displaying the User's address.

Why does this happen? Would it have happened if we had not used DynaForms?
If I haven't explained this clearly enough, pls let me know.

Thanks.
 
kayal cox
Ranch Hand
Posts: 376
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am thinking this might have something to do with the fact that I have action forwards in my submit methods. Maybe it is picking up these values from the request's attributes?
 
Marshal
Posts: 15883
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The values are getting picked up from the request parameters. Whenever you submit a request to an Action, whether directly from a browser client or by forwarding from another action, the Struts request processor will try to match any request parameters with the current ActionForm's fields. Any matching fields will be populated with the parameter values.

1. User form ----(submit)---> UserAction
2. UserAction ----(forward)--> VendorAction
3. VendorAction ---(forward)--> vendor.jsp

Is your control flow something like the above?
 
kayal cox
Ranch Hand
Posts: 376
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that is what I think is happening.
Would you be able to suggest a way by which I can stop it from behaving like that...

Here is some more stuff that I found out:

In the struts-config.xml, if I have just this, it works alright:


But if I have this, it fails:


Thanks. Appreciate your help.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<forward name="success" path="/vendorInfo.do?methodToCall=display" redirect="true"></forward>
 
kayal cox
Ranch Hand
Posts: 376
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marc!
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should explain things more often...
anyway I think that should work because a redirect will create a new request. Since the request is new, Struts will not be able to find the old form (because it set it to request scope and the request it was set to is now gone).
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic