Search code examples
datatableprimefacesgetterupdating

Primefaces DataTable fires update THREE times


In the code shown below the button with update="testTable" fires Bean.getSensors call three times, but the button with update="@form" fires only one. Why?

<h:form id="form4" prependId="true">
    <p:commandButton value="id" update="testTable" process="@none"/>
    <p:commandButton value="@form" update="@form" process="@none"/>

    <p:dataTable id="testTable" value="#{bean.sensors}"
                    var="sensor"
                    rowStyleClass="#{sensor.alarm ? 'alarm' : null}">
        <p:column headerText="Name" style="min-width: 100px; width: 100px;">
            <h:outputText value="#{sensor.name}"/>
        </p:column>
        <p:column headerText="Value" style="min-width: 100px; width: 100px;">
            <h:outputText value="#{sensor.value}"/>
        </p:column>
    </p:dataTable>
</h:form>

Thanks for all!


Solution

  • This is normal. JSF and Primefaces need to call it multiple times. If You have performance issues, use lazy loading

     public List<Sensor> getSensors(){
        if(sensors == null){
           sensors = ejb.getSensors();
        }
        return sensors;
     }