从 Struts 2.3.33 迁移到 Struts 2.5.12 LocalizedTextUtil 被移除
我们尝试从 Struts 2.33 迁移到 Struts 2.5.12.
We tried to migrate from Struts 2.33 to Struts 2.5.12.
我们在应用程序中直接使用了LocalizedTextUtil
.
We used LocalizedTextUtil
in our application directly.
我发现 LocalizedTextUtil
已从 com.opensymphony.xwork2.util.LocalizedTextUtil
中删除.我试图搜索但找不到任何东西
I found that the LocalizedTextUtil
is removed from com.opensymphony.xwork2.util.LocalizedTextUtil
. I tried to search but could not find any thing
我发现了一些类,如 StrutsLocalizedTextProvider
和 GlobalLocalizedTextProvider
但似乎它们不是我可以使用的.
I found some classes like StrutsLocalizedTextProvider
and GlobalLocalizedTextProvider
but it seems they are not what I can use them.
我已查看 migration-guide,但找不到任何关于它.
I have reviewed migration-guide but could not find any comment about it.
有什么选择?
推荐答案
struts.xml应该设置为:
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" />
并且 CustomStrutsTextProviderFactory
可以添加捆绑包
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);
}
}
完整归功于@LukazLenart https://issues.apache.org/jira/浏览/WW-4829
Complete credits to @LukazLenart https://issues.apache.org/jira/browse/WW-4829
相关文章