开发者

struts 2 text tag with dynamic expression , how?

开发者 https://www.devze.com 2022-12-16 00:40 出处:网络
I need to supply the key dynamically from the action to the text tag <s:text name=\"<%=talkToUsInfo.messageKey%>\" />

I need to supply the key dynamically from the action to the text tag

<s:text name="<%=talkToUsInfo.messageKey%>" />  

but the name开发者_C百科 attribute on text tag is declared as false ( not sure why ? )

How do i get something like this working without changing the tld in the jar file ?


Take a look at OGNL

It might look like this

<s:text name="%{talkToUsInfo.messageKey}" />


Struts documentation says:

Instead, you should use the getText() method that you inherit when your Action extends XWork's ActionSupport:

<s:textfield name="lastName" label="getText('person.lastName')" />

So I used e.g.

<s:property value="getText('status' + #someObject.currentStatus)" />

instead of "s:text" and it worked.


I prefer to use OGNL and s:text and do not make a call to getText manually. You usually define a fixed prefix while add the dynamic part to it, so some thing like this could be used:

<s:text name="%{'student.types.'+currencyType}" />

The only time which I used getText inside the s:property was something like this (which needs some if/else if you wanted to use s:text ):

<s:property value="shouldCancelIt.equals(\"0\") ? 
                           getText('label.yes'):getText('label.no')" />
0

精彩评论

暂无评论...
验证码 换一张
取 消