views:

26

answers:

2

I'm iterating over an array of beans called 'classifications'. How do I access the parentID property within the tag? I tried %{parentID} but that does not work.

<s:iterator value="classifications" status="theStatus">
    <s:if test="%{parentID} == -1">
        <p>-1: <s:property value="subjectName" /></p>
    </s:if>
    <s:else>
        <p>not -1: <s:property value="subjectName" /></p>
    </s:else>
</s:iterator>
A: 

I don't do Struts2, but in normal JSP EL the expressions are only evaluated inside the curly braces. It also makes sense. E.g. <c:if test="${parentID == -1}" />. See if it helps to do the same in your Struts2 tags. A quick glance in their documentation learns me that this should indeed be the case.

BalusC
great thanks. this worked!
phpguy
You're welcome.
BalusC
A: 

I think you need to something like this this:

<s:iterator value="classifications" status="theStatus" id="c">
    <s:if test="#c.parentID == -1">
        <p>-1: <s:property value="#c.subjectName" /></p>
    </s:if>
    <s:else>
        <p>not -1: <s:property value="#c.subjectName" /></p>
    </s:else>
</s:iterator>

Depending on what version of struts you are using you may need to change the id attribute to var in the iterator tag.

Nate