我的需求:在Struts 2中,使用成员值动态生成表单元素名称。
我尝试过:<s:textarea name="employee_<s:property value='employeeNumber'/>"/>
网络浏览器中的结果代码:<textarea name="employee_<s:property value='employeeNumber'/>"></textarea>
我对网络浏览器代码的期望:<textarea name="employee_101"></textarea>
。 101
作为employeeNumber
仅用于演示。
请帮忙,谢谢!
最佳答案
在 Struts2 中,您始终可以在 Struts 标记的属性中使用 OGNL 表达式。只需提供值堆栈中的值即可。您应该知道操作 bean 位于其之上,并且拥有 employeeNumber
的 getter 应该返回所需的值 101
。
<s:textarea name="employee_%{employeeNumber}"/>
另请注意,Struts 不允许在有利于 OGNL 的属性中嵌套标签。
关于java - Struts2中,使用成员值动态生成表单元素名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23846474/