【发布时间】:2014-05-03 17:47:44
【问题描述】:
我是 Struts 2 和 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}]
这里的 List 名称是 ComboMeals,HashMap 名称是 authors。
我想以表格的形式显示这些值。我在 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)。
但它没有显示任何值。你能帮忙吗?
【问题讨论】: