使用p:commandButton而不是h:commandButton时未显示的消息

时间:2017-06-01 16:31:20

标签: jsf primefaces bean-validation messages

我正在使用带有PrimeFaces和Bean验证的JSF,但验证错误消息未显示在浏览器中,这是我尝试验证的页面:

<?xml version="1.0" encoding="ISO-8859-1" ?>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Cadastro de Conta</title>
</h:head>
<h:body>
<h1>Cadastro de Conta</h1>
<p:separator responsive="true" />
<h:form>
    <h3>Dados de Conta</h3>
    <p:selectOneRadio value="#{contaMB.conta.tipoConta}">
        <f:selectItem itemValue="Conta Corrente" itemLabel="Conta Corrente" 
    />
        <f:selectItem itemValue="Conta Poupança" itemLabel="Conta Poupança" 
    />
    </p:selectOneRadio>
    <br />
    <p:panelGrid columns="2" responsive="true">

        <p:outputLabel for="inputAgencia" value="Agencia:" />
        <p:inputText id="inputAgencia"
            value="#{contaMB.conta.contaUsuario.agencia}" readonly="true" 
        />

        <p:outputLabel for="inputConta" value="Conta:"
            indicateRequired="true" />
        <p:inputText id="inputConta"
            value="#{contaMB.conta.contaUsuario.conta}" readonly="true" />

        <p:outputLabel for="inputSenha" value="Senha" />
        <p:password id="inputSenha" value="#{contaMB.conta.senha}"
            feedback="true" inline="true" promptLabel="Digite sua senha"
            weakLabel="Senha fraca" goodLabel="Senha média"
            strongLabel="Senha forte" />
        <p:message for="inputSenha" />
    </p:panelGrid>
</h:form>
<p:separator responsive="true" />
<h:form>
    <h3>Dados do Usuário</h3>
    <p:panelGrid columns="3" responsive="true">

        <p:outputLabel for="inputNome" value="Nome:" />
        <p:inputText id="inputNome" value="#{contaMB.conta.usuario.nome}" />
        <p:message for="inputNome"/>

        <p:outputLabel for="inputCPF" value="CPF:" />
        <p:inputMask id="inputCPF" mask="999.999.999-99"
            value="#{contaMB.conta.usuario.cpf}" />
        <p:message for="inputCPF" />

        <p:outputLabel for="inputRG" value="RG:" />
        <p:inputMask id="inputRG" mask="99.999.999-9"
            value="#{contaMB.conta.usuario.rg}" />
        <p:message for="inputRG" />

        <p:outputLabel for="inputDataNasc" value="Data de Nascimento:" />
        <p:calendar id="inputDataNasc" pattern="dd/MM/yyyy" navigator="true"
            mask="true" value="#{contaMB.conta.usuario.dataNasc}" />
        <p:message for="inputDataNasc" />

        <p:outputLabel for="inputTelefone" value="Telefone:" />
        <p:inputMask id="inputTelefone" mask="(99)9999-9999?9"
            value="#{contaMB.conta.usuario.telefone}" />
        <p:message for="inputTelefone" />

        <p:outputLabel for="inputEmail" value="Email:" />
        <p:inputText id="inputEmail" value="#{contaMB.conta.usuario.email}" 
        />
        <p:message for="inputEmail" />

        <p:outputLabel for="inputLogradouro" value="Endereço:" />
        <p:inputText id="inputLogradouro"
            value="#{contaMB.conta.usuario.logradouro}" />
        <p:message for="inputLogradouro" />

        <p:outputLabel for="inputNumero" value="Número:" />
        <p:inputText id="inputNumero" value="#
        {contaMB.conta.usuario.numero}" />
        <p:message for="inputNumero" />

        <p:outputLabel for="inputCEP" value="CEP:" />
        <p:inputMask id="inputCEP" mask="99999-999"
            value="#{contaMB.conta.usuario.cep}" />
        <p:message for="inputCEP" />

    </p:panelGrid>
    <br />
    <p:commandButton value="Salvar" action="#{contaMB.salvar}" />
    <p:commandButton value="Cancelar" action="login" immediate="true" />
</h:form>
</h:body>
</html>

以下是使用Bean验证的实体:

@Entity
@Table(name = "usuario")
public class Usuario {
@NotEmpty(message = "Nome não pode ser vazio")
private String nome;
@NotEmpty(message = "O CPF deve possuir 11 caracteres")
@Length(min = 14, max = 14)
@Id
private String cpf;
@NotEmpty
@Length(min = 12, max = 12, message = "O RG deve possuir 9 caracteres")
private String rg;
@Past(message = "A data não pode ser futura")
private Date dataNasc;
@NotEmpty
@Length(min = 13, max = 14, message = "O telefone deve possuir 10 ou 11 
dígitos, incluindo DDD")
private String telefone;
@Email
private String email;
@NotEmpty
private String logradouro;
@NotEmpty
@Min(0)
private String numero;
@NotEmpty
@Length(min = 9, max = 9, message = "O CEP deve possuir 8 caracteres")
private String cep;

当我使用纯度JSF的Bean验证(使用&#34; h:&#34;标记)时,它可以正常工作,但是当我改为&#34; p:&#34;标签(Primefaces),消息没有显示,但验证工作正常,因为我无法执行命令按钮操作,直到我正确填充输入。

这是entire project,我认为所有的库都是正确的。可能是什么问题?

由于

0 个答案:

没有答案