I'm trying to update a dateTable from calendar dateSelect event. I'm a newbie using PrimeFaces and Tomcat.
This is my code
index.xhtml
<h:body>
...
<h:form id="cites">
<p:calendar id="calendari" value="#{indexBean.calendari}" mode="inline" locale="va">
<p:ajax event="dateSelect" listener="#{indexBean.onDateSelect}" update="taulaHores"/>
</p:calendar>
<p:dataTable id="taulaHores" var="hores" value="#{indexBean.hores}"
widgetVar="taulaHores" emptyMessage="Sense resultats"
filteredValue="#{indexBean.horesFiltrades}" style="width:1000px"
selection="#{indexBean.horaSeleccionada}" rowKey="#{hores.hora}">
<p:column selectionMode="single" style="width:16px;text-align:center"/>
<p:column id="horaCol" headerText="Hora">
<h:outputText value="#{hores.hora}">
<f:convertDateTime type="time" pattern="HH:mm"/>
</h:outputText>
</p:column>
<p:column id="numeroHistoriaColBis" headerText="NHC" >
<h:outputText value="#{hores.nhc}" rendered="#{not null}" />
<h:outputText value="Lliure" rendered="#{hores.nhc eq null}" />
</p:column>
<p:column id="nomColBis" headerText="Nom" >
<h:outputText value="#{hores.nom}" rendered="#{not null}" />
<h:outputText value="" rendered="#{hores.nom eq null}" />
</p:column>
<p:column id="lliangesColBis" headerText="Llinages" >
<h:outputText value="#{hores.llinages}" rendered="#{not null}" />
<h:outputText value="" rendered="#{hores.llinages eq null}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>
IndexBean.java
public IndexBean() {
omplirHores(new Date(System.currentTimeMillis()));
}
public void onDateSelect(SelectEvent event) {
omplirHores((Date)event.getObject());
}
private void omplirHores(Date dia){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
this.hores = GenericDAO.sql("SELECT Hores.hora as hora, Hores.numeroHistoria as nhc, Persona.nom as nom, Persona.llinages as llinages " +
"FROM Hores LEFT JOIN Persona ON Hores.numeroHistoria=Persona.numeroHistoria " +
"WHERE hora>='"+dateFormat.format(dia)+" 00:00:00' AND hora<='"+dateFormat.format(dia)+" 23:59:59'" +
"ORDER BY Hores.hora ASC;");
System.out.println("llistahores " + this.hores.size());
}
Then, when index.xhtml is loaded, dataTable 'taulaHores' is filled right. The problem is when I select a date in calendar, then the rows on dataTable disappear and is not updated with the new values from sql query.
For more information, I see in the log that the size of 'hores' is right.
Please, any ideas?
Thanks in advance
filteredValue="#{indexBean.horesFiltrades}"
property – luialfer