We used getText
in actions, setMessageKey
in validators and <s:text>
in jsp files for an i18n application.
When Struts 2 could not find a key in resource bundles it returns the key itself. For example form.transfer.confirm
.
How can we change this behavior in the way that instead of the key itself Struts2 returns empty string.
You need to create custom implementation of TextProvider
and override getText
methods in it.
1) Create class (e.g. EmptyDefaultTextProvider
) extending one of TextProvider
existing implementations (e.g. TextProviderSupport
).
2) Override all getText
methods like that:
public String getText(String key, String defaultValue) {
return super.getText(key, "");
}
3) Use your custom class as the default text provider. Put below in struts.xml.
<constant name="struts.xworkTextProvider" value="emptyDefaultTextProvider" />
<bean type="com.opensymphony.xwork2.TextProvider" name="emptyDefaultTextProvider"
class="packagepath.EmptyDefaultTextProvider" scope="default" />
来源:https://stackoverflow.com/questions/29946455/change-struts-2-i18n-classes-behavior-when-key-is-not-found