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