有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

contextmenu操作后未更新java datatable

我有这个密码:

            <p:contextMenu for="customersTable">  
            <p:menuitem value="Delete" update="customersTable" icon="ui-icon-close" actionListener="#{customerbean.onDeleteCustomer}"/>  
            </p:contextMenu>  


            <p:dataTable id="customersTable" var="customer" widgetVar="customerTable" value="#{customerbean.customerList}" paginator="true" rows="20" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="10,20,50,100" emptyMessage="#{text['table.customer.filter.notfound']}" filteredValue="#{customerbean.filteredCustomers}" editable="true" draggableColumns="true" rowKey="#{customer.id}" selection="#{customerbean.selectedCustomer}" selectionMode="single"> 

我的问题是,当我点击contextMenu中的“Delete”时,一切都正常工作,因为记录/行正在通过bean方法调用从后端删除,但是表没有更新以反映新数据


共 (2) 个答案

  1. # 1 楼答案

    更新时,必须提供dataTable的完整组件id

     <h:form id="frm">
      <p:contextMenu for="customersTable">  
            <p:menuitem value="Delete" update="frm:customersTable" icon="ui-icon-close"  actionListener="#{customerbean.onDeleteCustomer}"/>  
            </p:contextMenu>  
            <p:dataTable id="customersTable" var="customer" widgetVar="customerTable"         value="#{customerbean.customerList}" paginator="true" rows="20" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="10,20,50,100" emptyMessage="#{text['table.customer.filter.notfound']}" filteredValue="#{customerbean.filteredCustomers}" editable="true" draggableColumns="true" rowKey="#{customer.id}" selection="#{customerbean.selectedCustomer}" selectionMode="single"> 
    
    
    
     </h:form>
    
  2. # 2 楼答案

    好吧,我发现了问题所在——非常微不足道。我是从数据库中删除它,但不是从Primefaces用来在屏幕上渲染它的集合中删除。它需要从这两个文件中删除