Search code examples
javajsparrayliststrutshashset

How to fetch item from HashSet field property using Struts nested taglibs?


I am trying to traverse an ArrayList and Set collection objects, using Struts nested tag. I have attached snippet of my code.

<snested:iterate property="productsList" id="aProduct">
   <snested:iterate property="participantList" id="participant_item">
       ......
     <snested:text property="firstName" styleClass="text"/>
  </snested:iterate>
</snested:iterate>

Here participantList is Set and productsList is List. In above code I am getting following error:

Invalid argument looking up property: "productsList[0].participantList[0].firstName" of bean: "orderedProducts"
at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:887
at org.apache.struts.taglib.html.BaseFieldTag.prepareValue(BaseFieldTag.java:126)

But If I use List instead of Set collection it works fine.


Solution

  • The class HashSet is not an indexed collection. You can't use this class with the Struts nested tag.

    If the requirement to use Set instead of List is mandatory then you should change the tag or tag library used this tag or use another tag library, i.e. JSTL, etc.