Rasoul Taheri
Rasoul Taheri

Reputation: 822

Error in customizing jsf resource bundle handler

In a project i will customize the jsf resource bundle handler. according to this post:
i18n with UTF-8 encoded properties files in JSF 2.0 application

i add following lines to my 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>

And create a handler:

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);
    }
}  

But when is goto my page i get following Exception :

java.util.MissingResourceException: Can't find bundle for base name org.apache.myfaces.bundle.CustomJsfBundleHandler, locale en at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564) at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1387) at java.util.ResourceBundle.getBundle(ResourceBundle.java:1082) at org.apache.myfaces.application.ApplicationImpl.getResourceBundle(ApplicationImpl.java:459) at org.apache.myfaces.application.ApplicationImpl.getResourceBundle(ApplicationImpl.java:435) at org.apache.myfaces.el.unified.resolver.ResourceBundleResolver.getResourceBundle(ResourceBundleResolver.java:222) at org.apache.myfaces.el.unified.resolver.ResourceBundleResolver.getValue(ResourceBundleResolver.java:136)

Do you have any idea?

Upvotes: 1

Views: 729

Answers (2)

Klaus
Klaus

Reputation: 46

If you still need an answer: I today had the same problem and the solution is the following: You have to implement it similarly to the solution mentioned in this thread: https://stackoverflow.com/a/3646601/6650315

In your mentioned example the fully classified class name of the custom resource bundle is org.apache.myfaces.bundle.CustomJsfBundleHandler which is correctly set as base-name in the faces-config.xml. Inside the folder src/main/resources the directory structure org/apache/myfaces/bundle has to be created and inside the last directory a file named customJsfBundleHandler.properties (and customJsfBundleHandler_de.properties...) has to be created. So the complete filepath should be src/main/resources/org/apache/myfaces/bundle/customJsfBundleHandler.properties

So the conclusion is:

  • The fully classified classname of your custom bundle implementation defines the base-name which has to be mentioned in the faces-config.xml.
  • The fully classified classname (base-name) defines the complete directory structure inside of src/main/resources
  • The simple classname defines the name of the properties file, written in camelCase

Upvotes: 0

Rapster
Rapster

Reputation: 524

From what I read, your CustomJsfBundleHandler is not doing much so far. Make sure you have a messages.properties in org/apache/myfaces/bundle/CustomJsfBundleHandlerfolder under src/main/resources folder

Upvotes: 0

Related Questions