struts 2文本标签用动态表达,怎么样?

Sur*_*rya 6 struts2

我需要动态地从动作提供密钥到文本标记

<s:text name="<%=talkToUsInfo.messageKey%>" />  
Run Code Online (Sandbox Code Playgroud)

但是text标签上的name属性被声明为false(不知道为什么?)

如何在不更改jar文件中的tld的情况下获得此类工作?

tev*_*vch 6

看看OGNL吧

它可能看起来像这样

<s:text name="%{talkToUsInfo.messageKey}" />
Run Code Online (Sandbox Code Playgroud)


Leo*_*nid 3

Struts 文档说:

相反,您应该使用您的 Action 扩展 XWork 的 ActionSupport 时继承的 getText() 方法:

<s:textfield name="lastName" label="getText('person.lastName')" />
Run Code Online (Sandbox Code Playgroud)

所以我用了例如

<s:property value="getText('status' + #someObject.currentStatus)" />
Run Code Online (Sandbox Code Playgroud)

而不是“s:text”并且它有效。