My requirement: In Struts 2, dynamically generate form element name by using member value.
I had tried with: <s:textarea name="employee_<s:property value='employeeNumber'/>"/>
Resulting code in web browser: <textarea name="employee_<s:property value='employeeNumber'/>"></textarea>
My expectation in web browser code: <textarea name="employee_101"></textarea>
. 101
as an employeeNumber
is only used for demonstration only.
Please help, thanks!
In Struts2 you can always use OGNL expression in the Struts tag's attribute. Just provide the value from the value stack. You should know that the action bean is on top of it, and having a getter for employeeNumber
should return desired value 101
.
<s:textarea name="employee_%{employeeNumber}"/>
Also be aware of Struts doesn't allow nested tags in the attributes in favor of OGNL.