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 java-jsf java-jsf-resource-bundle

Edit on github
comments powered by Disqus
Click me