To access the index value of struts iterator in scriptlet array index

我是研究僧i 提交于 2019-12-05 07:35:57

The current iteration index is available via the status attribute of the s:iterator tag. In your case is #incr.index. If you want to display that index

<s:iterator value="images" status="incr"> 
  <s:property value="%{#incr.index}"/>

then scriplet could be changed to OGNL expression

<s:property value='#attr.imageCaptionsString.split(",")[%{#incr.index}]'/>

After struggling a lot and with the help of answer suggested by Mr. Roman C, I got the solution and keeping here for sake of any future needy user.

<s:iterator value="images" status="incrementer">
  <s:set var="cnt" value="%{#incrementer.index}" />
  <s:property value="#attr.imgCaptions.get(#cnt)"/>
</s:iterator>

This way I got the captions. Thanks to Mr. Roman C.

This should do

<s:iterator value="imageCaptionsString.split(",")">  
    <s:property/>
</s:iterator>

If that doesn't work, then might be because it's a request attribute & hence, not available directly on valueStack, in which case you can use #attr.imageCaptionsString instead of plain imageCaptionsString in the iterator.

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