0

I want a custom JSP tag that has an attribute which is a normal bean expression and names a list. The tag shall then render the list in a specific form.

I tried to write a custom tag with an attribute for s:iterator like this:

<%@ tag body-content="empty"%>
<%@ attribute name="list" required="true"  %>

<%@ taglib prefix="s" uri="/struts-tags"%>

<s:set var="varList" >${list}</s:set>
<s:iterator value="varList">(render item)</s:iterator>

In a different JSP I used it with a bean expression:

<my:listtag list="myObject.aList"/>

I expected it to iterate over "myObject.aList" but unfortunately this doesn't work. What seems to happen is, that the iterator tries to iterate over "myObject" instead of "myObject.aList".

What's going on and how can I get my desired bahaviour?

Thank you very much!

1 Answer 1

0

Okay, here we go. The Attribute must be defined of type "Collection" and the iterator variable must be given by "%{#attr.list}":

<%@ attribute name="list" required="true" type="java.util.Collection" %>

<s:iterator value="%{#attr.list}">(render item)</s:iterator>

In the other JSP I need to call it with the value of the variable, not the variable name:

<my:listtag list="${myObject.aList}"/>

yay!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.