简体   繁体   English

primefaces如何更新数据表

[英]primefaces how to update datatable

How can i update datatable in primefaces.Datatable updates only when i refresh the page. 我如何更新primefaces.datatable更新数据表只有当我刷新页面时。 I have found some solutions but none of them worked for me.For example when i change update to ":companyForm:companyPanel" save button disappers. 我找到了一些解决方案,但它们都没有为我工作。例如,当我将更新更改为“:companyForm:companyPanel”时,保存按钮消失。 I removed colon and now i can see button but still doesn't update datatable. 我删除了冒号,现在我可以看到按钮,但仍然不更新数据表。 Here is my jsf page; 这是我的jsf页面;

<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. 实际上你的ids搞砸了,否则组件会被刷新。

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> . 组件的实际客户端ID取决于标记所在的命名容器。在这种情况下,命名容器为<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 . 当您在表单标记中包含prependId="false"属性时,嵌套<p:panel id="companyPanel">的客户端ID将是companyPanel ,否则(如果您完全省略prependId ) - 它将是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. 仍然,因为您想要在同一命名容器(窗体)中更新组件,您不需要在其<p:commandButton update="companyPanel">表单ID,并且只需<p:commandButton update="companyPanel"> :没有冒号且没有表单id,有没有。

In the state your code is now, there is no component with id companyForm:companyPanel . 在您的代码现在的状态中,没有id为companyForm:companyPanel组件companyForm:companyPanel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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