The only change required in UserBean.java is:
package com.corejsf; import java.io.Serializable; import javax.inject.Named; import javax.enterprise.context.SessionScoped; @Named("user") @SessionScoped public class UserBean implements Serializable { private String name = ""; private String password; public String getName() { return name; } public void setName(String newValue) { name = newValue; } public String getPassword() { return password; } public void setPassword(String newValue) { password = newValue; } public String getGreeting() { if (name.length() == 0) return ""; else return "Welcome to JSF2 + Ajax, " + name + "!"; } }
Adding a method named getGreeting creates a greeting property for user. Since there is no setGreeting method this property is read-only.
public String getGreeting() { if (name.length() == 0) return ""; else return "Welcome to JSF2 + Ajax, " + name + "!"; }