So I have this form on my login.xhtml:
<h:form id="login">
<p:graphicImage url="img/logo.jpg" width="448" height="119"/>
<p> Si pertenece a una empresa, inserte su usuario y password. </p>
<p:outputLabel for="usuario" value="Usuario:" />
<p:inputText id="usuario" value="#{loginController.login.username}"/>
<p:outputLabel for="password" value="Password:" />
<p:password id="password" value="#{loginController.login.password}"/>
<p:commandButton value="Login" update="out" actionListener="#{loginController.login()}"/>
<h:outputText id="out" />
<a href="#"> Si no pertenece a una empresa, haga click para continuar</a>
</h:form>
When the button is clicked, this method is activated:
public String login() {
login = service.login(login.getUsername(), login.getPassword());
if (login.getUsername() == null) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Usuario y/o password incorrecto!"));
return null;
} else {
return "index.jsf?faces-redirect=true";
}
}
I am trying to validate if the user exists or not but using AJAX. So if the username and password are incorrect, I want it to display the message on the <h:outputText>
without reloading the page. If it is successful, I want the redirect to happen. None of these are working.
What am I doing wrong?