java - How to set end attribute dynamically with Struts2 iterator in JSP -
<% registeraction aro=new registeraction(); int count=aro.getli().size(); %> <s:iterator value="li" begin="0" end="1"> <fieldset> name : <s:property value="name" /><br/> password : <s:property value="password" /><br/> email : <s:property value="email" /><br/> gender : <s:property value="gender" /><br/> country : <s:property value="country" /><br/> </fieldset> </s:iterator>
how set end
attribute value dynamically iteration, reading count
variable ?
if use end="<%=count%>"
not working.
if use end="count"
it's working getting same result multiple of numbers if refresh page or reload.
you can use #attr
notation in ognl read variables set within scritplet blocks, if push them in pagecontext:
<% registeraction aro = new registeraction(); int count = aro.getli().size(); pagecontext.setattribute("count", count); // pushing variable pagecontext %> <s:iterator value="li" begin="0" end="%{#attr['count']}"> <fieldset> name : <s:property value="name" /><br/> password : <s:property value="password" /><br/> email : <s:property value="email" /><br/> gender : <s:property value="gender" /><br/> country : <s:property value="country" /><br/> </fieldset> </s:iterator>
but you should never use scriptlet for many reasons.
it's easy use struts tags instead of scriptlets purposes, like shown in answer.
edit:
if use
end="count"
it's working getting same result multiple of numbers if refresh page or reload.
it's unclear why instantiating action in scriptlet block, , why expect result of count different across page loadings, since code referring collection in initial state.
if registeraction your current action, want probably:
<s:iterator value="li" begin="0" end="%{li.size()}">
that in fact
<s:iterator value="li">
and overcomplicating simple iteration factor 2337.
Comments
Post a Comment