We tried to migrate from Struts 2.33 to Struts 2.5.12.
We used LocalizedTextUtil
in our application directly.
I found that the LocalizedTextU
The struts.xml should be set as:
<constant name="struts.xworkTextProvider" value="DefaultTextProvider" />
<bean type="com.opensymphony.xwork2.TextProvider" name="DefaultTextProvider" class="utils.CustomTextProvider" scope="default" />
And CustomStrutsTextProviderFactory
could add bundles
public class MyTextProviderFactory implements TextProviderFactory {
protected LocaleProviderFactory localeProviderFactory;
protected LocalizedTextProvider localizedTextProvider;
@Inject
public MyTextProviderFactory(LocaleProviderFactory localeProviderFactory, LocalizedTextProvider localizedTextProvider) {
this.localeProviderFactory = localeProviderFactory;
this.localizedTextProvider = localizedTextProvider;
this.localizedTextProvider.addDefaultResourceBundle("messages/label");
this.localizedTextProvider.addDefaultResourceBundle("messages/customerA/label");
}
@Override
public TextProvider createInstance(Class clazz) {
TextProvider instance = getTextProvider(clazz);
if (instance instanceof ResourceBundleTextProvider) {
((ResourceBundleTextProvider) instance).setClazz(clazz);
((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider());
}
return instance;
}
@Override
public TextProvider createInstance(ResourceBundle bundle) {
TextProvider instance = getTextProvider(bundle);
if (instance instanceof ResourceBundleTextProvider) {
((ResourceBundleTextProvider) instance).setBundle(bundle);
((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider());
}
return instance;
}
protected TextProvider getTextProvider(Class clazz) {
return new TextProviderSupport(clazz, localeProviderFactory.createLocaleProvider(), localizedTextProvider);
}
protected TextProvider getTextProvider(ResourceBundle bundle) {
return new TextProviderSupport(bundle, localeProviderFactory.createLocaleProvider(), localizedTextProvider);
}
}
Complete credits to @LukazLenart https://issues.apache.org/jira/browse/WW-4829
You should use StrutsLocalizedTextProvider or GlobalLocalizedTextProvider. They have some util api, however it's marked as deprecated. Happily, it's documented in the javadoc.
I'm referencing source code from the repo because I was unable to find these classes in javadoc for Struts 2 Core 2.5.11-SNAPSHOT API