How to solve the date validation problem - Calendar - Primefaces?

Asked

Viewed 1,317 times

1

Loading the date in a Calendar (Primefaces) normally loads:

Code:

<p:outputLabel value="Data de Nascimento" for="data-nascimento" />
<p:calendar id="data-nascimento" locale="pt" mask="99/99/9999"
            value="#{solicitacaoRHBean.itemEdicao.dataNascimento}"
            required="true" navigator="true"
            requiredMessage="Data de Nascimento é obrigatório">
</p:calendar>

But at the time of validating/persisting the information gives error message saying that the date is not a valid date.

How to resolve this issue?

inserir a descrição da imagem aqui

  • 2

    I’m afraid the problem is in "Mask", as the attribute itself points out, it’s just a mask. Try using the "Pattern" attribute instead of Mask: pattern="dd/MM/yyyy".

  • 1

    If you are looking for another alternative, I think it would be more feasible to use the Hibernate Validation Bean to make the validations. Following example: http://blog.caelum.com.br/java-ee-6-comecando-bean-validation/

  • Patrick, I traded the Mask for Pattern and it worked thanks.

1 answer

1


To the locale="pt" work, you need add a javascript on your page because by default it is only in English.

Mask is just a mask, not the formatting itself. However, you can force the Brazilian pattern using the attribute and value pattern="dd/MM/yyyy".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.