I´m using Primefaces, I have an input field whose value must be generated in relation to an input date, the problem is that the date can be selected by clicking on the calendar or typing, if done in the first way everything works correctly but if done by writing, the value of UIInput in the backing bean is null. I dont know why the binding attribute is not working right or what i´m doing wrong.
<p:calendar id="fechaContable"
value="#{movimientoBean.movimientoCab.fechaContable}" pattern="dd/MM/yyyy" binding="#{movimientoBean.fecha}" required="true"
requiredMessage="Se necesita fechaContable">
<p:ajax event="dateSelect" oncomplete="document.getElementById('anadirForm:numeroAsiento').focus()"/>
</p:calendar>
<p:inputText id="numeroAsiento"
binding="#{movimientoBean.numeroAsiento}" value="#{movimientoBean.movimientoCab.numeroAsiento}" required="false">
<f:ajax event="focus" render=":anadirForm:numeroAsiento" listener="#{movimientoBean.numAsiento}"/>
</p:inputText>
The backing bean
@ManagedBean
@ViewScoped
public class MovimientoBean implements Serializable{
......
private transient UIInput numeroAsiento;
private transient UIInput fecha;
......
public void numAsiento(){
.....
try {
Date date = dateFormat.parse(fecha.getValue().toString());
fechaContable = sdf.format(date);
}catch (ParseException e){
}
}
When dateSelect is invoked, the value of UIInput fecha is right, but when the date is written it is null.
Sorry for possible grammar or spelling mistakes
EDIT(Solution):
Here is the code working in case someone needs it, thanks to Laabidi Raissi for his help and the information:
<p:calendar id="fechaContable"
value="#{movimientoBean.movimientoCab.fechaContable}" pattern="dd/MM/yyyy" required="true"
requiredMessage="Se necesita fechaContable">
<p:ajax event="dateSelect" update=":anadirForm:numeroAsiento" listener="#{movimientoBean.numAsiento}" oncomplete="document.getElementById('anadirForm:numeroAsiento').focus()"/>
<p:ajax event="change" update=":anadirForm:numeroAsiento" listener="#{movimientoBean.numAsiento}" oncomplete="document.getElementById('anadirForm:numeroAsiento').focus()"/>
</p:calendar>
<p:inputText id="numeroAsiento"
value="#{movimientoBean.movimientoCab.numeroAsiento}" required="false">
</p:inputText>