Update Datatable - Ajax cellEdit (Primefaces )

Asked

Viewed 538 times

1

Hello, I’m trying to update Datatable but I’m not getting it. Follow the code:

<h:form id="testeForm" >
 <p:panel toggleable="true" id="panelTeste">                
    <h:panelGrid columns="1" cellpadding="1" id="panelGridTeste">

       <p:dataTable  id="dataTableTeste" var="teste" value="#{testeController.listaTeste" editable="true" editMode="cell" >

          <p:ajax event="cellEdit" listener="#{testeController.atualizarDataTable}"  update=":testeForm:dataTableTeste"/>

          <p:columnGroup type="header">
             <p:row>
                <p:column headerText="Col1" />
                <p:column headerText="Col2" />
                <p:column headerText="Col3" />
             </p:row>
          </p:columnGroup>

          <p:column>
             <p:cellEditor>
                <f:facet name="output"><h:outputText value="#{teste.valorCol1}" /></f:facet>
                <f:facet name="input"><p:inputText value="#{teste.valorCol1}" /></f:facet>
             </p:cellEditor>
          </p:column>

          <p:column>
             <p:cellEditor>
                <f:facet name="output"><h:outputText value="#{teste.valorCol2}" /></f:facet>
                <f:facet name="input"><p:inputText value="#{teste.valorCol2}" /></f:facet>
             </p:cellEditor>
          </p:column>

          <p:column>
             <h:outputText value="#{teste.valorCol3}" />
          </p:column>
       </p:dataTable>
    </h:panelGrid>
 </p:panel>
</h:form>

testeController:

public void atualizarDataTable(CellEditEvent event) {           
    for (Teste teste : listaTeste) {
       valorCol3 = valorCol1 + valorCol2;
    }
}

Everything works correctly, I just can’t update Datatable information.

Does anyone know how I can do it?

I tried with the p:remoteCommand and it works if after I edit Cell press enter but not work if you leave the field with the key tab (which is what I need).

I’m trying to update on Controller/Bean with RequestContext.getCurrentInstance().update("testeForm:dataTableTeste"); and it’s not working either... No update.

Thank you

  • Anyone? I believe there is no way to do it the way I need to. Will with p:hotkey???

  • 1

    You really need to put that path on update=":testeForm:dataTableTeste" ? And where the method variables come from atualizarDataTable()? So I see you didn’t update because he hasn’t processed your table yet. try to put a process="@this" in ajax.

  • 1

    I usually put one p:ajax in each input. <p:inputText value="#{teste.valorCol1}" > <p:ajax event="change" process "@this" update="testeForm:dataTableTeste"/></p:inputText >. With this every time you edit a value in your table it will process and update it.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.