struts 2 if to test value of iterator
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>
精彩评论