Ammad
Ammad

Reputation: 4225

Struts2 if condition using string list

I have Array list called matrixList, on which i am iterating. I want to display different value if return value from getStatus() method equals to value "GREEN" .For some reason i am getting error "target is null for method equals"

<s:iterator status="stat" value="matrixList">
  <tr>
    <s:if test="%{#status.equals('GREEN')}">
      THIS IS green
    </s:if>

    <td class="R0C1"><s:property value="status"/></td>
    <td class="R0C1"><s:property value="releaseTarget"/></td>
  </tr>
</s:iterator>

Any idea what I'm missing?

Upvotes: 1

Views: 762

Answers (2)

Dave Newton
Dave Newton

Reputation: 160261

Omit # if status is on the value stack (as opposed to a named value in the stack context):

<s:if test="%{status.equals('GREEN')}">

If <s:property value="status"/> works why reference it differently in the <s:if> tag?

Upvotes: 2

Invisible Arrow
Invisible Arrow

Reputation: 4925

The property name used in the if statement should be stat and not status.

<s:if test="%{#stat.equals('GREEN')}">

This is because the name of the variable in the iteration scope is defined as stat in the status = "stat" statement.

Upvotes: 0

Related Questions