1
votes

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

2
I've noticed that if I press F5 after the date selection, the content of the table is updatedluialfer
SOLVED!!! Just removing filteredValue="#{indexBean.horesFiltrades}" propertyluialfer
You don't need to yell "SOLVED!!!" in titles and post the answer in edit summary or a question comment. I rollbacked the title edit. Just post the answer as an answer here below. This way the question will appear in listing and search as "answered". When you then mark the answer accepted, then the question will also appear in listing and search as "solved". This is a Q&A site, not an old fashioned discussion forum or so.BalusC

2 Answers

1
votes

Solved just removing filteredValue="#{indexBean.horesFiltrades}" property

-1
votes

After updating datatable you have to invoke it's client side filter() method.

<p:calendar id="calendari" value="#{indexBean.calendari}" mode="inline" locale="va">
  <p:ajax event="dateSelect" listener="#{indexBean.onDateSelect}" update="taulaHores" oncomplete="PF('taulaHores').filter()"/>
</p:calendar>