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 overridegetText
methods in it.1) Create class (e.g.
EmptyDefaultTextProvider
) extending one ofTextProvider
existing implementations (e.g.TextProviderSupport
).2) Override all
getText
methods like that:3) Use your custom class as the default text provider. Put below in struts.xml.