在一个项目中,我将自定义jsf资源包处理程序。根据这篇文章:
i18n with UTF-8 encoded properties files in JSF 2.0 application
我在我的faces-config中添加以下行:
<application>
<locale-config>
<default-locale>fa</default-locale>
<supported-locale>en</supported-locale>
<supported-locale>fa</supported-locale>
</locale-config>
<message-bundle>ApplicationResources</message-bundle>
<resource-bundle>
<base-name>org.apache.myfaces.bundle.CustomJsfBundleHandler</base-name>
<var>messages</var>
</resource-bundle>
</application>
并创建处理程序:
package org.apache.myfaces.bundle;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.PropertyResourceBundle;
public class CustomJsfBundleHandler extends PropertyResourceBundle {
public CustomJsfBundleHandler(InputStream stream) throws IOException {
super(stream);
}
public CustomJsfBundleHandler(Reader reader) throws IOException {
super(reader);
}
@Override
public Object handleGetObject(String key) {
// do some customization
return super.handleGetObject(key);
}
}
但是当进入我的页面时,出现以下异常:
java.util.MissingResourceException:找不到基本名称为org.apache.myfaces.bundle.CustomJsfBundleHandler的包,语言环境en 在java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564) 在java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1387) 在java.util.ResourceBundle.getBundle(ResourceBundle.java:1082) 在org.apache.myfaces.application.ApplicationImpl.getResourceBundle(ApplicationImpl.java:459) 在org.apache.myfaces.application.ApplicationImpl.getResourceBundle(ApplicationImpl.java:435) 在org.apache.myfaces.el.unified.resolver.ResourceBundleResolver.getResourceBundle(ResourceBundleResolver.java:222) 在org.apache.myfaces.el.unified.resolver.ResourceBundleResolver.getValue(ResourceBundleResolver.java:136)
你有什么主意吗?
答案 0 :(得分:0)
据我了解,到目前为止,您的CustomJsfBundleHandler做得还不够。确保在messages.properties
文件夹下的org/apache/myfaces/bundle/CustomJsfBundleHandler
文件夹中有一个src/main/resources
答案 1 :(得分:0)
如果您仍然需要答案:我今天也遇到了同样的问题,解决方案如下:您必须类似于此线程中提到的解决方案来实现它:https://stackoverflow.com/a/3646601/6650315
在您提到的示例中,自定义资源束的完全分类的类名称为org.apache.myfaces.bundle.CustomJsfBundleHandler
,已在faces-config.xml
中正确设置为基本名称。在文件夹src/main/resources
内,必须创建目录结构org/apache/myfaces/bundle
,在最后一个目录内,必须创建名为customJsfBundleHandler.properties
(和customJsfBundleHandler_de.properties
...)的文件。因此,完整的文件路径应为src/main/resources/org/apache/myfaces/bundle/customJsfBundleHandler.properties
所以结论是:
faces-config.xml
中提及的基本名称。src/main/resources
内的完整目录结构