0
votes

How can i update datatable in primefaces.Datatable updates only when i refresh the page. I have found some solutions but none of them worked for me.For example when i change update to ":companyForm:companyPanel" save button disappers. I removed colon and now i can see button but still doesn't update datatable. Here is my jsf page;

<h:form id="companyForm" prependId="false">
  <p:panel id="companyPanel">
    <p:dataTable id="companyListTable">
     //columns
    </p:dataTable>
  </p:panel>

<p:outputPanel id="newDatePanel">
  <p:commandButton value="Save"                                         
    update="companyForm:companyPanel
    companyForm:newDatePanel"                                         
    action="#{myController.save()}"/>
</p:outputPanel>
</form>

and my spring controller;

init(){
    companyList = service.getAllCompany();
}

public void save(){
    service.save(company);
}
1
what is the scope of your managed bean ? - Laabidi Raissi
since you are making prependId="false" then in the update don't put the form id, it should be like this, update=":companyListTable" - Laabidi Raissi
"I removed colon and now it works", your code work fine ? - Rong Nguyen
"I removed colon and now i can see button but still doesn't update datatable" - Laabidi Raissi
You try: update=":#{p:component('companyListTable')}" - Rong Nguyen

1 Answers

2
votes

Actually you have your ids messed up, otherwise the components would have been refreshed.

The actual client id of your component depends on the naming container your tag's in. In this case, the naming container is <h:form>. As you included prependId="false" property in your form tag the client id of a nested <p:panel id="companyPanel"> would be companyPanel, otherwise (if you omitted prependId altogether) - it would be companyForm:companyPanel.

Still, as you want to update component within the same naming container (form), you don't need to prefix it with a form id and let it be simply <p:commandButton update="companyPanel">: without colon and without form id, be there any.

In the state your code is now, there is no component with id companyForm:companyPanel.