[英]What is the Struts2 equivalent for <bean:message> tag with property attribute in Struts1? For example:<bean:message name="user" property="label" />
在 Struts 1 中, <bean:message>
標簽通常與 key 屬性一起使用,以便通過在 key 屬性中指定 message-key 從屬性文件中獲取消息。
在 struts 2 中,我們使用<s:text>
或<s:property>
標簽來做到這一點。
考慮下面的例子: 在 struts 1 中, <bean:message key="user.name.required"/>
Struts 2 中的等價物是,
<s:text name="user.name.required" />
或<s:property value="getText('user.name.required')"/>
其中, user.name.required = Name is required
是內容的屬性文件。
但我對不同的情況感到困惑。 <bean:message name="user" property="label" />
為此,我嘗試了<s:property value="getText('label')"/>
但返回的值是字符串"label"
而不是消息字符串"User data is missing"
我也試過<s:property value="label"/>
但是返回的值是消息鍵,即"user.data.missing"
而不是消息字符串"User data is missing"
<bean:message name="user" property="label" />
在 Struts 1 中返回消息用戶數據丟失。 其中, user.data.missing=User data is missing
屬性文件的內容。
我的問題是如何在 Struts 2 中實現這一點?
試試下面的代碼
<s:property value="getText(label)"/>
其中label
是值堆棧中的一個變量,其中包含一個消息鍵,即"user.data.missing"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.