简体   繁体   中英

primefaces how to update datatable

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);
}

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM