My JSP receives an ArrayList
of beans from a Struts2 action.
I want to iterate over them and print every bean and its properties per line.
How can I do this using Struts2 tags?
My JSP receives an ArrayList
of beans from a Struts2 action.
I want to iterate over them and print every bean and its properties per line.
How can I do this using Struts2 tags?
Using JSTL:
<c:forEach items="${list}" var="item">
<c:out value="${item.property}" />
</c:forEach>
You will have to add JSTL to the classpath, because it isn't shipped with Struts, but it shoul work. Of course, using struts' own tag (as shown by BalusC) is a better option.
Use <s:iterator>
tag.
<s:iterator value="beans">
<p>Property foo: <s:property name="foo" /></p>
<p>Property bar: <s:property name="bar" /></p>
</s:iterator>
An overview of all tags can be found in their own documentation: tag reference. Bookmark it.