How to do it...

  1. Let's create a User class as the main object of our recipe:
public class User implements Serializable {    private String name;    private String email;    public User(String name, String email) {        this.name = name;        this.email = email;     }       //DON'T FORGET THE GETTERS AND SETTERS    //THIS RECIPE WON'T WORK WITHOUT THEM}
  1. Now, we create a UserBean class to manage our UI:
@Named@ViewScopedpublic class UserBean implements Serializable {    private User user;        public UserBean(){        user = new User("Elder Moraes", "elder@eldermoraes.com");    }    public void userAction(){        FacesContext.getCurrentInstance().addMessage(null,                 new FacesMessage("Name|Password welformed"));    }    //DON'T FORGET THE GETTERS AND SETTERS    //THIS RECIPE WON'T WORK WITHOUT THEM}

Get Java EE 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.