• 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

nested:iterate Index Incorrect

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

My Jsp looks somewhat like this:
<nested:form action="/proposalMedical" >
...
<nested:iterate name="ProposalMedicalForm" property="proposalMedicalRateForm" id="proposalMedicalRateForm" indexId="rateIndexId" >
...
<nested:iterate name="proposalMedicalRateForm" id="proposalMedicalInfoForm" property="proposalMedicalInfoForm" indexId="infoIndexId" >
...

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.

RateForm1
>Info1

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!
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nancy O'Connell
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Popeye has his spinach. I have this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!