I want to reuse a set of HTML field elements and have struts build 'name' attributes from a variable. I saw this How To Generate unique HTML id attributes within Struts 2 iterator tag and figured I could use something similar but can't get it to work. It seems I can build a name attribute from a struts variable only in an iterator loop. How can I do this with a simple variable instead?
Here is my code, first trying to use a variable, the second using an 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 the first not substituting the variable, and the iterator loop working.
Why doesn't it work and how can I do this?