Wednesday, May 23, 2012

JSF page does not properly set object attributes

Simple question from a beginner at JSF:

I have very simple JSF form:

<h:inputText value="#{}" />

<h:inputSecret value="#{userServiceImpl.user.password}" />

<h:commandButton value="#{messages.loginButtonLogin}" action="#{userServiceImpl.authenticateUser}" />

The userServiceImpl class is:

public class UserServiceImpl implements UserService {

private UserSession userSession;
private User user;

public UserServiceImpl(UserSession userSession) {
this.userSession = userSession;

public void prepareService() {
user = new User();

public View authenticateUser() {
return View.MAIN;

public User getUser() {
return user;

public void setUser(User user) {
this.user = user;


My goal is pretty simple: when the user hits the login button, I want to authenticate the user.

The problem is:
When the authenticate method is called, the User attributes are null. I debugged the application and the getUser method is called and the values are properly set, but at some point (which I did not find [yet]) before the authenticateUser is called the User attributes are set to null...

I'm aware that this is a pretty basic question... but are you able to point out where my mistake is?


No comments:

Post a Comment