代码之家  ›  专栏  ›  技术社区  ›  Opu

如何使用Struts嵌套标记库从HashSet字段属性中提取项?

  •  1
  • Opu  · 技术社区  · 7 年前

    我想穿过一个 ArrayList Set 集合对象,使用Struts嵌套标记。我已经附上了我的代码片段。

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

    在这里 participantList 设置 productsList List 。 在上述代码中,我遇到以下错误:

    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)
    

    但如果我使用 列表 而不是 设置 收集它工作得很好。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Roman C    7 年前

    班级 HashSet 不是索引集合。不能将此类与Struts嵌套标记一起使用。

    如果要求使用 Set 而不是 List 是必需的,那么您应该更改使用此标记的标记或标记库,或者使用另一个标记库,如JSTL等。