Struts2 JSP s:s:iterator里面的迭代器

时间:2014-05-03 17:47:44

标签: jsp struts2 iterator

我是Struts 2& S的新手JSP。这个问题可能很愚蠢;请耐心等待,如果是的话。我在我的Java程序中创建了以下结构 - 我有一个包含HashMaps的ArrayList。一个样本如下:

[{Name = S S. Peter,Email = xyz @ yahoo.com,Type = P / C,Location = New York},{Name = Tom Hanks,Email = tom.hanks@gmail.com ,Type = C / A,Location = null},{Name = Carl Zeiss,Email = null,Type = C / A,Location = null}]

此处列表名称为ComboMeals,HashMap名称为作者。

我想以表格的形式显示这些值。我在JSP中使用以下构造:

    <s:iterator value="comboMeals">
 <div class="Row" align="left">
     <s:iterator value="authors" var="numbers"> 
        <s:set var="authorTypeKey" value="key" />
            <div class="Cell" align="left">
                <s:if test="%{#authorTypeKey=='Type'}">
                    <p><s:textfield name="selectedTypeTxtBox" value="%{authors.Type}"></s:textfield><br>
                    <s:select list="listOfTypes" name="selectedType" value="%{authors.Type}" onchange="getSelectedType(this)"></s:select><br><br></p>
                </s:if>
                <s:elseif test="%{#authorTypeKey=='Name'}">
                    <p><s:textfield name="selectedNameTxtBox" value="%{authors.Name}"></s:textfield><br>
                    <s:select  list="listOfNames" name="selectedName" value="%{authors.Name}" onchange="getSelectedName(this)"></s:select><br><br></p>
                </s:elseif>
                <s:elseif test="%{#authorTypeKey=='Location'}">
                     <p><s:textfield  name="selectedLocationTxtBox" value="%{authors.Location}"></s:textfield><br>
                    <s:select list="listOfLocations" name="selectedLocation" value="%{authors.Location}" onchange="getSelectedLocation(this)"></s:select><br><br></p>
                </s:elseif>
                <s:elseif test="%{#authorTypeKey=='Email'}">
                     <p><s:textfield name="selectedEmailTxtBox" value="%{authors.Email}"></s:textfield><br>
                    <s:select list="listOfEmails" name="selectedEmail" value="%{authors.Email}" onchange="getSelectedEmail(this)"></s:select><br><br></p>
                </s:elseif>
            </div>
      </s:iterator>
 </div> 

- 请忽略onChange事件的JavaScript(这适用于s:select)。

但它没有显示任何值。能帮忙吗?

1 个答案:

答案 0 :(得分:0)

由于您使用的是var,请从中读取值,而不是从可迭代源中读取(不指定索引):使用value="%{authors.Something}"更改选择框中的所有value="%{numbers.Something}"

同时阅读:

  1. All the ways to read an iterated object(index,var,top)
  2. How to deal with nested Collections / Maps in Struts2(通过创建包装对象)
  3. P.S:为了更好的帮助,下次考虑发布您的java对象和声明,而不是(或除了)对象的内容。

相关问题