通过迭代在Struts2
问题描述:
2周的ArrayList parallell我有两个数组列表通过迭代在Struts2
private ArrayList<String> userPics = new ArrayList<String>();
private ArrayList<String> picLikes = new ArrayList<String>();
第一个ArrayList包含图像的路径和其他列表中包含的节数喜欢每一个画面了。我需要使用迭代器标记在struts2中并行获取值。怎么做..?
答
假设您“链接”它们与索引,你可以使用IteratorStatus喜欢如下:
<s:iterator value="userPics" var="pics" status="ctr">
Current Element from userPics: <s:property value="pics" />
Current Element from picLikes: <s:property value="picLikes[%{#ctr.index}]" />
</s:iterator>
但它会更好,10次创造与这两个属性的对象,和列表其中:
public class Picture {
private byte[] picture;
private int likes;
/* getters and setters */
}
然后在动作:
private List<Picture> pics;
/* getter and setter */
并最终在您的JSP中:
<s:iterator value="pics">
Current Element from userPics: <s:property value="picture" />
Current Element from picLikes: <s:property value="likes" />
</s:iterator>
它们如何相互链接? – 2014-11-05 09:19:21