I am new to Java EE and developing first Java EE login application using netbeans 7.1.2. I have db table & entity named 'Users' with few naded queries, a session bean 'UsersFacade' containing persistance unit, and method named 'authenticaate' below is code
public Users authenticate(String login_id, String pwd) {
Users user = (Users) em.createNamedQuery("Users.authenticate")
.setParameter("login_name", login_id)
.setParameter("password", pwd)
.getResultList().get(0);
finally i have jsf managed bean which is sessionscoped containing two local members login_name and password, jsf page login.xhtml is bound with these fields, this bean also has authenticate method which in turn calls session bean 'UserFacade' authenticate message
@ManagedBean
@SessionScoped
public class Login implements Serializable {
private String login_name;
private String password;
private Users user;
private @EJB UsersFacade user_services;
public String authenticate() {
user = user_services.authenticate(this.getLogin_name(),this.getPassword());
if (user != null){
return "home";
} else {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage("login", new FacesMessage("Invalid UserName and Password"));
return "login";
}
every thing works fine till this point. However, on home page i want to display all data members of users table so that i can modify values and save record. in home page i coded like:
<h:outputText value="Welcome #{login.user.login_name}" />
assuming i have declared user (entity) in managed bean and i should be able to access property of entity but when i run application, i get following error:
The class 'controller.Login' does not have the property 'user'
can any one suggest what i am doing wrong and what is ideal way of binding jsf page with managed bean if i have 3 different implementations for 1 managed bean (3 different user interface for 3 different role/types of users). I am using JPA (entity,session) & JSF managed bean. Thank you so much.