我有一個JSF項目,我正在嘗試做一個登錄頁面,在我的項目中我有一個託管的bean,它擁有用戶名和密碼的validate方法,並且我有一個包含setter的bean類和獲取者,其中有用戶信息填充數據庫如(用戶名,密碼,isActive,全名),我的問題是如何在我的xhtml頁面中調用JSF el表達式中的用戶信息,如果他們不在託管bean?JSF bean和對象
這是我的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";
}
}
}
你能告訴我們你的代碼嗎? –
沒有得到託管bean? –
@khalilM我想訪問託管bean,並且只有在託管的bean中複製了我的實例變量和setter以及getter時才能訪問它們,但是這樣做沒有意義嗎?我很抱歉,但我是JSF的新手 – Khaled