在一个项目中,我将自定义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,java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564)中的locale,位于java.util.ResourceBundle.getBundleImpl( ResourceBundle.java:1387)位于org.apache.myfaces.application.ApplicationImpl的org.apache.myfaces.application.ApplicationImpl.getResourceBundle(ApplicationImpl.java:459)的java.util.ResourceBundle.getBundle(ResourceBundle.java:1082) .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)
你有什么主意吗?
从我读到的,你的CustomJsfBundleHandler到目前为止做得不多。确保你在messages.properties
文件夹下的org/apache/myfaces/bundle/CustomJsfBundleHandler
folder中有一个src/main/resources