Olá, notei que que o h:message ( http://java.sun.com/jsf/html) não funciona no Codigo abaixo, mas o p:message do Prime faces sim. Podem me explicar o porque?
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Agenda Java - Login</title>
</h:head>
<h:body>
<h:form>
<p:messages id="messages" showDetail="true" autoUpdate="true"
closable="true" />
<p:fieldset legend="Login" style="margin-bottom:20px">
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="login" value="Usuário" />
<p:inputText id="login" value="#{loginBean.usuario.email}"
validator="#{loginBean.validaemail}" required="true" >
</p:inputText>
<p:outputLabel for="senha" value="Senha" />
<p:password id="senha" feedback="true" inline="false"
value="#{loginBean.usuario.senha}" required="True"
requiredMessage="Insira a senha!" />
<p:commandButton id="submit" value="submit" type="submit"
action="#{loginBean.login}" />
</h:panelGrid>
<h:messages />
</p:fieldset>
</h:form>
</h:body>
</html>
package com.agendajava.bean;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;
import javax.xml.bind.ValidationException;
import com.agendajava.Dao.LoginDao;
import com.agendajava.model.Usuario;
//@WebServlet(urlPatterns = "/login")
@ManagedBean(name = "loginBean")
public class LoginBean {
Usuario usuario = new Usuario();
public Usuario getUsuario() {
return usuario;
}
public void setUsuario(Usuario usuario) {
this.usuario = usuario;
}
public String login() {
if (new LoginDao().login(usuario)) {
return "contatos?faces-redirect=true";
} else {
FacesContext.getCurrentInstance().addMessage("submit", new FacesMessage("Login ou Senha Incorretos!"));
}
return "Falha na Autenticação";
}
public void validaemail(FacesContext fc, UIComponent component,Object value) throws ValidatorException{
String valor = value.toString();
if(valor.contentEquals("alexandre")){
throw new ValidatorException(new FacesMessage("Você é o Alexandre você não pode Entrar"));
}
}
}