开发者

struts 2 iterator with range

I have an array of strings. Lets say array[] containing 5 strings: "a", "b", "c", "d", "e" Now I want to display 开发者_运维问答only strings at position 3 and 4 in the jsp file. How do I do that with s:iterator tag ? (just like a normal for loop starting at 3 and ending at 4)

Is there a way to loop with s:iterator with a begin and end value just like a normal loop ?

Thanks!


Why not just use iterator tag with begin and end attributes.
Example from Struts2 tag reference:

<s:iterator value="{1,2,3,4,5}" begin="2" end="4" >
    <!-- current iteration value (2,3,4) -->
    <s:property value="top" />
</s:iterator>


You can have a look at http://www.vaannila.com/struts-2/struts-2-example/struts-2-iterator-tag-example1.html to see the iterator properties that are available for your use so you can create conditional statements like "if loop is at position 3 of the array, then print the value"

Alternatively, you can also try s:subset tag. See http://struts.apache.org/2.0.14/docs/subset.html for more info.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜