问题描述
struts.xml应设置为:
<constant name="struts.xworkTextProvider" value="DefaultTextProvider" />
<bean type="com.opensymphony.xwork2.TextProvider" name="DefaultTextProvider" class="utils.CustomTextProvider" scope="default" />
并CustomStrutsTextProviderFactory
可以添加捆绑
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);
}
}
完整积分@LukazLenarthttps://issues.apache.org/jira/browse/WW-4829
解决方法
我们试图从Struts 2.33迁移到Struts 2.5.12。
我们LocalizedTextUtil
直接在应用程序中使用过。
我发现将LocalizedTextUtil
删除了com.opensymphony.xwork2.util.LocalizedTextUtil
。我试图搜索但找不到任何东西
我发现了一些类似的类StrutsLocalizedTextProvider
,GlobalLocalizedTextProvider
但似乎它们不是我可以使用的类。
我已经查看了迁移指南,但找不到对此的任何评论。
有哪一种选择?