开发者

struts 2 if to test value of iterator

开发者 https://www.devze.com 2023-02-08 03:07 出处:网络
Am using struts 2 iterator and if tag can anyone tell me how to test a particular value of iterator Example: I got a Li开发者_StackOverflow中文版st of type String with values

Am using struts 2 iterator and if tag can anyone tell me how to test a particular value of iterator

Example: I got a Li开发者_StackOverflow中文版st of type String with values

StrList = {"start","hello","hi","name","start","value",.."start",..} I want to test for start if start is found i want to display HI and else Hello.


<s:if StrList.contains("start")>
  Display HI
</s:if>
<s:else>
  Display HELLO
</s:else>

Untested please see S2 web site tag lib documentation. Also assumed StrList was a public field, otherwise it should be called strList and have an appropriate getter/setter (as that would be following Java conventions).

Edit: I didn't read the question well enough... Use the var attribute of the iterator to give each iteration of the iterator a convinent handle, like so:

<s:iterator value='{"start","something","start","something else","start"}' var="curStr">
  <s:if curStr.compareTo("start")>  //or perhaps compareToIngnoreCase()
    Display HI
  </s:if>
  <s:else>
    Display HELLO
  </s:else>
</s:iterator>
0

精彩评论

暂无评论...
验证码 换一张
取 消