I have a pretty standard struts application, but am having an unusual problem, at least one that I've never seen. There is a MedicalForm bean, which has an ArrayList of RateForms. Each RateForm has an arrayList of detailed InfoForms. I am displaying and allowing the user to update the order of the InfoForms on the screen.
Everything displays correctly - if I have one RateForm with 3 InfoForms, that's what shows up on the screen.
RateForm1 >Info1 >Info2 >Info3
When I submit the screen, the information is mapped back to the form incorrectly. Instead of one RateForm, I now have 3 RateForms, and each RateForm has one InfoForm. In addition, each InfoForm shows up in it's original position in the arraylist. On the first RateForm, Info1 shows up in the first position in the arrayList. On the second RateForm, Info2 shows up in the position of the arrayList, with the first position being null. On the third RateForm, Info3 shows up in the third position of the arraylist.
RateForm2 >null >Info2
RateForm3 >null >null >Info3.
Has anyone ever encountered a problem like this before or have any ideas? I'm guessing the indexes for the RateForms are getting updated incorrectly, but I'm not sure why. Thanks!
I've had problems with using the nested:xxx tags in conjunction with indexed properties. You can't always trust that they will render the way that you want them to. My rule of thumb is that if I have indexed properties that are nested more than one level deep, I always manually build the indexed property rather than relying on the nested tags. Example:
The above example assumes that you either have a Servlet version 2.4 compliant application, or that you are using the struts-el version of the tags. Otherwise, you will have to use scriptlets instead of EL expressions.
Thanks for your reply, I agree the nested tags are flaky. Unfortunately, I'm not using struts-el. I did get this to work correctly by cleaning up my tags - some of my nested tags still had name paramaters and indexed="true" parameters included. Once I deleted all those un-needed paramters, and made sure that all my tags in the iteration were nested, all values and indexes were returned correctly.