Tuhra Home Errata Code Listing Downloads
TUHRA Logo

Code Listings

Book Cover

Chapter 9
Section V1. Add Navigation and Validation Logic to the Application
Code loginButton_action() code

FacesContext messageContext = FacesContext.getCurrentInstance();

String returnResult = "login";
loginAttempts++;

if (!passwordField.getValue().toString().equals("JSF"))
{
  returnResult = null;
  if (loginAttempts >= 3)
  {
    // message displayed in the messages tag
    messageContext.addMessage(null, new FacesMessage("You seem " +
        " to have forgotten that the password is \"JSF.\""));
  }
  else
  {
    messageContext.addMessage(null,
    new FacesMessage("Incorrect login. Try again."));
  }
}
else
{
  loginCountField.setValue(loginAttempts);
  loginAttempts = 0;
  passwordField.setValue(null);
}

return returnResult;