[英]Iterate two Lists in struts2
I have two lists, selectedFields
which contains the headers (eg: id
, username
, firstname
) and custDetails
which contains customer details(eg: id
, username
, firstname
, birthdate
, address
etc.). 我有两个列表, selectedFields
包含标题(例如: id
, username
, firstname
)和custDetails
,其中包含客户详细信息(例如id
, username
, firstname
, birthdate
, address
等)。 what I want to do here is print only the data from custDetails
in <td>
which are contained in selectedFields
.if selectedFields contains username then only the username values will be shown like <td>John</td>
and header will be like <th>username</th>
. 我想在这里做的是只打印来自<td>
custDetails
的数据,这些数据包含在selectedFields
如果selectedFields包含用户名,则仅用户名值将显示为<td>John</td>
而标题将为<th>username</th>
。
<table>
<thead>
<!-- Selected Fields contains id,username -->
<s:iterator value="selectedFields">
<th><s:property/></th>
</s:iterator>
</thead>
<tbody>
<!-- custDetails contains id,username,firstname,lastname,address,city,state etc. -->
<s:iterator value="custDetails" status="custDetails">
<tr>
<s:iterator value="selectedFields" status="selectedFields">
<!-- Display only id,username columns from custDetails since selectedFields contains these values -->
<td><s:property value="<s:property />"/></td>
</s:iterator>
</tr>
</s:iterator>
</tbody>
</table>
You can use if
and else
tags to choose which columns you want to display. 您可以使用if
和else
标记来选择要显示的列。 Unless you don't want to iterate the object properties. 除非您不想迭代对象的属性。
<s:iterator var="sf" value="selectedFields">
<!-- Display only id,username columns from custDetails since selectedFields contains these values -->
<s:if test="#sf == 'id'">
<td><s:property value="id"/></td>
</s:if>
<s:else>
<s:if test="#sf == 'username'">
<td><s:property value="username"/></td>
</s:if>
</s:else>
</s:iterator>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.