tags:

views:

44

answers:

3

Hi guys,

I want to use my message bundle (messages_fr.properties) in a Java class with seam.

In a jsf file, all work fine like this:

<h2>#{msg.newCustomer}</h2>

But in my Java class, I tried to do this:

statusMessages.addToControlFromResourceBundle("refArbor", "#{messages['error_refArborDoesntExist']}");

or this:

statusMessages.addToControlFromResourceBundle("refArbor", "error_refArborDoesntExist");

or again this:

statusMessages.addToControlFromResourceBundle("refArbor", "#{msg.error_refArborDoesntExist}");

But the message showned is:

error_refArborDoesntExist

And not the real message.

How can I use my bundle is a Java class ?

Thanks.

+2  A: 

I usually inject the resource bundle, or the resource into the class and use it from there. Example:

@In("#{messages['name']}")
private String name

Or,

@In
private Map<String, String> messages;

wich injects the resourceBundle as a Map. (make sure the it's named messages in this case).

Albert
With it, the Map messages is empty, how do you declare messages.properties in components.xml ?
Kiva
+1  A: 

There are a number of ways you can do it.

StatusMessages.instance().addFromResourceBundle("msg.newCustomer);
//This will add the msg.newCustomer message to the view

String msg = org.jboss.seam.international.Messages.instance().get("msg.newCustomer);
//This will put the msg.newCustomer message in variable msg
Shervin
What is the package for Messages class ?
Kiva
`org.jboss.seam.international.Messages`Answer is edited
Shervin
+1  A: 

It's working with your solution:

@In
private Map<String, String> messages;

Just place the messages.properties in WEB-INF/classes/

Kiva