1

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?

Rasoul Taheri
  • 802
  • 3
  • 16
  • 32

2 Answers2

0

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

Rapster
  • 484
  • 1
  • 5
  • 23
0

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
Klaus
  • 46
  • 5
  • Look at omnifaces and deltaspike. Solves a lot of this for you – Kukeltje Jan 16 '20 at 18:47
  • Thx @Kukeltje for that information. We removed Omnifaces from our project 1 or 2 years ago and needed a solution without that, that's why I also stumbled over this problem. 2020-01-17 Edit: Added information about case-sensitivity in Linux and so camelCase-usage in `faces-config.xml` is needed, if the property files are also named camelCase – Klaus Jan 17 '20 at 10:03
  • Why did you remove Omnifaces? Sounds like some sort of automutulation – Kukeltje Jan 17 '20 at 10:14