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.
posted 15 years ago
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?
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?
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
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).