tagged: jsf-resource-bundle

JSF2: Databinding with ManagedBeans

First create a standard POJO with a @ManagedBean annotation so it can be accesssed via databinding. Give it a @SessionScoped annotation to say it exists for the entirity of the user's session:
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

public class SomeData implements Serializable {

    private String name = "";

    public SomeData() {

    public String getName() {
	return name;

    public String getNameInfo() {
	if(name.equals("Dave")) {
		return "David, huh. Intereseting...";
	} else {
		return "Hmmm! Nothing on you.";

    public void setName(String user_name) {
	this.name = user_name;

Now in your JSF page you can edit the name variable by the following InputText and see it's result also:
    <h:inputText value="#{someData.name}">
<br />

java jsf jsf-resource-bundle

JSF2: Resource bundles / localisation

In your WEB-INF folder place a faces-config.xml file:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.0"
	      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">


You're saying your resource bundle is called things.properities in the root your your classes directory, and you can access it in your JSF page via 'bundle'. We're saying we support both english and french.
Now create that things.properties file. I'm putting it in my resources/ folder. You need to make sure this ends up in the root of your classes directory.

In your jsf page you can access it via:

If you have a things_fr.properties file, and your browser is set to French, it will use the french version for the resources bundle.

jsf jsf-resource-bundle

Page 1 of 1