Struts 2 Iteration tag with hasNext()

von

I needed a while until i figured out, how I could create a comma separated list with the Struts 2 Iteration tag. Of course after the last element no comma should appear. I have tried it with the hasNext() method, but somehow could not access the parent iteration. Glad I found the status attribute, which returns an easy to use IteratorStatus. From there you can create such a list pretty easy. Here is a JSON String which holds a list of ActionErrors:

<s:if test="hasActionErrors()">
{"error":[
<s:iterator value="actionErrors" status="errorStatus">
  "<s:property escape="false" />"<s:if test="#errorStatus.isLast() != true">,</s:if>
</s:iterator>
]}
</s:if>

Tags: #Apache Struts #Java

Newsletter

ABMELDEN