简体   繁体   中英

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?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM