How to compare list items (type string) and string (in query area) using struts 2 tags

My list contains items ("A", "B", "C", "D")

<s:iterator value="lis">
  <s:property /><br>
</s:iterator>

and String str = "A";

<s:property value="%{#request.str}"/>

I want to compare each list item (lis) with the string s.

+2
source share
1 answer

With an IteratorStatus object:

<s:iterator value="lis" status="ctr">
    <s:property /> 
    <s:if test="%{#request.str.equals(lis[#ctr.index])}">
        -> This value from "lis" is equal to the value of "str"
    </s:if>
    <br/>
</s:iterator>

With the var parameter :

<s:iterator value="lis" var="currentValue">
    <s:property /> 
    <s:if test="%{#request.str.equals(#currentValue)}">
        -> This value from "lis" is equal to the value of "str"
    </s:if>
    <br/>
</s:iterator>

With keyword top:

<s:iterator value="lis">
    <s:property /> 
    <s:if test="%{#request.str.equals(top)}">
        -> This value from "lis" is equal to the value of "str"
    </s:if>
    <br/>
</s:iterator>

You can read a short one OGNL Language Guidefor more details.

+2
source

All Articles