Datatable does not update after successful ajax call

后端 未结 6 487
广开言路
广开言路 2021-01-12 06:17

I have a data table. Each row of the table has a commandButton called \'Remove\', which is supposed to remove that row from the model and the view and

相关标签:
6条回答
  • 2021-01-12 06:44

    You are probably using Primefaces 2.2.1 as this seems like it is due to a common bug with the Primefaces dataTable component. Essentially what occurs is that ajax postbacks occurring from within elements of a dataTable will not result in a partial page update of elements in the dataTable.

    The simplest workaround is to invoke a postback from a button outside of the dataTable where its sole purpose is simply to partial page update the dataTable. This is not the most efficient solution as it results in two postbacks, however it does work.

    See my previous answer to this problem Here

    0 讨论(0)
  • 2021-01-12 06:44

    I had filters in my datatable. So here I resolved the problem with

    oncomplete="PF('myWidgetVar').filter()" and update="@form"
    
    0 讨论(0)
  • 2021-01-12 06:48

    I recognize this problem form one of our current PF 3.0 pages. It will work if you use update="@form" instead. I haven't really had the time to investigate the real cause so that I can report it to the PF guys, because this problem does not manifest in all pages. Even in the same table, a different button works as intented.

    Give it a try:

    <p:commandButton update="@form" ... />
    

    Update: coming to think about it, it's maybe related to the presence of process="@this".

    0 讨论(0)
  • 2021-01-12 06:51

    This is the solution to refresh in jsf 2.0

    <p:dataTable  id="empl1" var="emp" value="#{dtEmployeeView.employee}" selectionMode="multiple"  rowKey="#{emp.id}"
                                  paginator="true" rows="5" tableStyleClass="ui-table-columntoggle">
        <p:column width="20" headerText="Id"  priority="1">
            <h:link value="#{emp.id}" />
        </p:column>
        <p:column headerText="Employee Name" priority="2">
            <h:outputText value="#{emp.pname}" />
        </p:column>
    
    </p:dataTable>
    <p:commandButton update="form1:empl1" ajax="true" value="Submit" action="#{empService.addEmployee(employee)}" >
        <f:event type="preRenderView" listener="#{dtEmployeeView.init()}"/>
    </p:commandButton>
    
    0 讨论(0)
  • 2021-01-12 06:58

    If you want to use server IDs for updating components (like userTable, somethingElse, ...), these components need to be in the same naming container as the component which triggers the update (your button for example). Otherwise you need to use an expression like this within the update attribute: update=":usersForm:userTable".

    The main problem is to identify the naming containers. The outer button does work, because it is in the same naming container (the form) as the table with the ID userTable. The facet gets updated because the whole table gets updated, but since datatable is a naming container itself, it should not be possible to update the footer by just using update="somethingElse" on the outer button.

    I'm not sure, why the inner button does not work. I guess there is another naming container within the datatable. PrimeFaces does log an INFO, if the component could not be found using the findComponent algorithm of the UIComponent implementation. INFO: Cannot find component with identifier "userTable" in view.

    0 讨论(0)
  • 2021-01-12 07:00

    I was using update="@form" and it didn't completely work: it wasn't updating the number of rows in the dataTable, for instance. What I already had in place was this on the button that updated the form:

    process="@this" oncomplete="updateRC();"

    and then just below I had:

    <p:remoteCommand name="updateRC" process="@this" update="@form" />


    What I did to fix the rows update problem is add a styleClass to the dataTable, e.g. "myTable", and then add a jQuery selector to that class in the above remoteCommand, e.g.:

    <p:remoteCommand name="updateRC" process="@this" update="@form @(.myTable)" />

    0 讨论(0)
提交回复
热议问题