JSF豆和对象



我有一个JSF项目,我正在尝试执行一个登录页面,在我的项目中,我有一个托管bean,它具有用于用户名和密码的验证方法,我有一个带有设定器和获取器的BEAN类,其中包含用于数据库的用户信息。例如(用户名,密码,ISARTIVE,全名),我的问题是,如果他们在XHTML页面中,我该如何调用JSF EL表达式中的用户信息,如果他们在XHTML页面中不在托管豆吗?

这是我的java bean:

@Table(name="students_info")
public class User {
    @Column(name="std_record_id")
    private int id;
    @Column(name="std_id")
    private String userId;
    @Column(name="first_name")
    private String firstName;
    @Column(name="web_password")
    private String password;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
}

这是我的mblogin:

    @ManagedBean
    @SessionScoped
    public class MBLogin {
        User user = new User();
        LoginDAO loginDao = new LoginDAO();
        public String validteStudent() {
            boolean valid = loginDao.validateStudent(user.getUserId(), user.getUserId());
            if (valid) {
                HttpSession session = SessionUtils.getSession();
                session.setAttribute("username", user);
                return "student";
            } else {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
                        "Incorrect Username and Passowrd", "Please enter correct username and Password"));
                return "login";
            }
        }
    }

为用户添加getter:

@ManagedBean
    @SessionScoped
    public class MBLogin {
        User user = new User();
        LoginDAO loginDao = new LoginDAO();
        public String validteStudent() {
            boolean valid = loginDao.validateStudent(user.getUserId(), user.getUserId());
            if (valid) {
                HttpSession session = SessionUtils.getSession();
                session.setAttribute("username", user);
                return "student";
            } else {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
                        "Incorrect Username and Passowrd", "Please enter correct username and Password"));
                return "login";
            }
        }
        public User getUser() {
            return user;
        }
    }

然后在您的XHTML中可以这样称呼:
#{user.id}#{user.firstName}

相关内容

  • 没有找到相关文章

最新更新