how to compare list elements(type string) and string(in request scope) using struts 2 tags

安稳与你 提交于 2019-11-26 14:49:32

问题


My List contains("A","B","C","D") elements

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

and String str="A";

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

I want to compare every element of list(lis) with String s.


回答1:


With the 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 the top keyword:

<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 may wanna read the short OGNL Language Guide for more details.



来源:https://stackoverflow.com/questions/19515742/how-to-compare-list-elementstype-string-and-stringin-request-scope-using-str

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!