JSF 1.2 Application.getMessageBundle () returns null

I am using Spring 2.5 with JSF 1.2 , on Tomcat 6.0.13 .

In one part of the code, I am trying to load a ResourceBundle using the following approach:

ResourceBundle.getBundle(context.getApplication().getMessageBundle(), Locale.EN); 

The problem is that the getMessageBundle () method returns null . This was used to work with JSF 1.1 . Does anyone know what could be the problem?

At the moment, I'm going to specify the name of the hardcode package, but I would prefer that all my configuration data be placed inside faces-config.

The resource package is installed as follows:

  <application> <locale-config> <default-locale>en</default-locale> </locale-config> <resource-bundle> <base-name>org.mysite.MessageBundle</base-name> <var>msgs</var> </resource-bundle> </application> 
+4
source share
2 answers

getMessageBundle() returns the value of the <message-bundle> entry in faces-config.xml , not the <resource-bundle> entry.

Its value is not actually accessible by the JSF 1.2 API. You must specify it yourself.

 ResourceBundle bundle = context.getApplication().getResourceBundle(context, "org.mysite.MessageBundle"); 

<message-bundle> is for validation / conversion messages. You probably used this in JSF 1.1.

+2
source

Igorb,

You might be able to use resource nesting so that the JSF provides the managed bean with the correct ResourceBundle. This saves you from having to hardcode something in your Java source and keep in touch in a centralized organization.

Start by defining a managed property based on your bean. In the JSF configuration, set the value of the managed property to an EL expression that references your resource package.

I did something like the following with Tomcat 6. The only caveat is that you cannot access this value from your bean constructor, since JSF has not initialized it yet. Use @PostConstruct according to the initialization method if the value is required at the beginning of the bean life cycle.

 <managed-bean> ... <managed-property> <property-name>messages</property-name> <property-class>java.util.ResourceBundle</property-class> <value>#{msg}</value> </managed-property> ... </managed-bean> <application> ... <resource-bundle> <base-name>application_messages</base-name> <var>msg</var> </resource-bundle> ... </application> 
+3
source

All Articles