Error - JSF and PrimeFaces

0

Error when trying to register user, the following message appears:

accordion:dtNasc: '22-02-1990' could not be understood as a date.

XHTML:

<p:outputLabel class="lt" value="Data de Nascimento:" />
<p:calendar id="dtNasc" value="#{usuarioBean.funcionario.dt_nasc}" locale="pt" yearRange="-99:+39" widgetVar="dtNasc"navigator="true" showButtonPanel="true">
<f:convertDateTime pattern="dd/MM/yyyy" />
</p:calendar>

Class Officer

@NotEmpty(message = "O campo data de nascimento é obrigatório.")
@Column(name = "fun_dt_nasc", nullable = false)
private String dt_nasc;


public String getDt_nasc() {
    return new SimpleDateFormat("dd/MM/yyyy").parse(getDt_nasc());
}
public void setDt_nasc(String dt_nasc) {
    setDt_nasc(new SimpleDateFormat("dd/MM/yyyy").format(dt_nasc));
}

On my get it gives an error: Type mismatch: can not convert from Date to String

    
asked by anonymous 18.05.2016 / 14:15

1 answer

2

As you said, your dt_nasc attribute is of type String and Calendar needs to be of type Date.

Either you change this or create a method to convert, for example:

public Date getDtNasc(){
    return new SimpleDateFormat("dd/MM/yyyy").parse(getDt_nasc());
}
public void setDtNasc(Date data){
    setDt_nasc(new SimpleDateFormat("dd/MM/yyyy").format(data));
}

And in your xhtml:

<p:calendar id="dtNasc" value="#{usuarioBean.funcionario.dtNasc}" locale="pt" yearRange="-99:+39" widgetVar="dtNasc"navigator="true" showButtonPanel="true">
    <f:convertDateTime pattern="dd/MM/yyyy" />
</p:calendar>
    
19.05.2016 / 17:01