jsp - Using <s:set /> to dynamically build element's name -
i want reuse set of html field elements , have struts build 'name' attributes variable. saw how generate unique html id attributes within struts 2 iterator tag , figured use similar can't work. seems can build name attribute struts variable in iterator loop. how can simple variable instead?
here code, first trying use variable, second using iterator :
<s:set var="type" value="main" /> <s:textfield name="prefix%{#type}.name"/> <s:set var="alist" value="{'main'}" /> <s:iterator value="alist" var="ltype"> <s:textfield name="prefix%{#ltype}.name"/> </s:iterator>
this generates 2 elements :
<input type="text" name="prefix.name" value=""> <input type="text" name="prefixmain.name" value="">
with first not substituting variable, , iterator loop working.
why doesn't work , how can this?
you assigning value first variable, not string literal, , since there isn't an object called main
in valuestack, assigning an empty string type
variable:
<s:set var="type" value="main" />
while doing (almost) great in second example:
<s:set var="alist" value="{'main'}" />
just use
<s:set var="alist" value="%{'main'}" />
or
<s:set var="alist" value="'main'" />
everywhere , work.
{}
alone useless , dangerous, because has special meaning in ognl (list projection, list selection, etc.)
Comments
Post a Comment