2014-02-28 39 views
1

我有一個Purchase數據表在列出所有購買的選項卡中。當您選擇一行時,應該打開一個對話框,顯示特定客戶的購買清單。在代碼中還有一個對話框用於添加新購買,其中可以從數據表中的先前客戶列表中選擇CustomerJSF PrimeFaces row選擇從另一個數據表中調用的一個數據表

我的問題是,當我選擇的,而不是觸發它自己的rowSelect事件在購表人它呼籲在客戶數據表的rowSelect AJAX事件(從「新購」對話框內)的行打開的Purchase對話框。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:p="http://primefaces.org/ui" 
    xmlns:c="http://java.sun.com/jstl/core" 
    xmlns:o="http://omnifaces.org/ui" 
    xmlns:of="http://omnifaces.org/functions"> 
<h:head> 

</h:head> 
<h:body> 

    <p:growl id="messages" showDetail="true" /> 

    <h:form id="newPurchaseCommandForm" enctype="multipart/form-data"> 
     <p:commandButton value="New Purchase" process="@this" 
      onclick="PF('newPurchase').show()" id="btnNewPurchase"> 
      <f:actionListener binding="#{purchasesDAO.init()}" /> 
     </p:commandButton> 
    </h:form> 

    <p:tabView id="tabView" dynamic="true" cache="true" scrollable="true" 
     style="font-size:12px;"> 

     <p:tab id="tba1" title="Purchase List"> 
      <h:form id="purchaseTableForm" enctype="multipart/form-data"> 
       <p:dataTable id="PurchaseTable" var="purchaseVar" 
        rowKey="#{purchaseVar.id}" 
        selection="#{purchasesDAO.selectedPurchaseRow}" 
        widgetVar="purchasesTableSearch" 
        filteredValue="#{purchasesDAO.filteredPurchaseRow}" 
        selectionMode="single" value="#{purchasesDAO.purchaseList}" 
        style="font-size:10px;"> 

        <!-- Opens dialog --> 
        <p:ajax event="rowSelect" listener="#{purchasesDAO.onRowSelect}" 
         update=":messages" oncomplete="PF('showPurchase').show()" /> 

... 
       </p:dataTable> 
      </h:form> 
     </p:tab> 

    </p:tabView> 

    <p:dialog header="Purchase Details" widgetVar="showPurchase" 
     id="dialog" resizable="true" modal="false" hideEffect="explode" 
     height="500" width="990"> 

... 

    </p:dialog> 


    <p:dialog header="Add New Purchase" widgetVar="newPurchase" 
     id="dialogNewPurchase" resizable="true" modal="true" hideEffect="explode" 
     closeOnEscape="true" height="600" width="900"> 
     <h:form id="form-newcasedialog" enctype="multipart/form-data"> 

      <p:dataTable id="CustomerTable" var="customer" 
       rowKey="#{customer.id}" 
       selection="#{purchasesDAO.selectedCustomerRow}" 
       widgetVar="purchasesTableSearch" 
       filteredValue="#{purchasesDAO.filteredCustomerRow}" 
       selectionMode="single" value="#{purchasesDAO.customerList}" 
       style="font-size:10px;"> 

       <!-- Opens dialog --> 

       <p:ajax event="rowSelect" listener="#{purchasesDAO.onRowSelect3}" 
        process="@this" /> 
... 
       </p:dataTable> 

     </h:form> 
    </p:dialog> 

</h:body> 
</html> 

回答

1

這個解決方案花了我很多時間才發現,但它原來是一個簡單的單行錯字。 的widgetVar同時爲客戶表和購買表是相同的:

<p:dataTable id="CustomerTable" var="customer" 
    rowKey="#{customer.id}" 
    selection="#{purchasesDAO.selectedCustomerRow}" 
    widgetVar="purchasesTableSearch" 
    filteredValue="#{purchasesDAO.filteredCustomerRow}" 
    selectionMode="single" value="#{purchasesDAO.customerList}" 
    style="font-size:10px;"> 

應該是:

<p:dataTable id="CustomerTable" var="customer" 
    rowKey="#{customer.id}" 
    selection="#{purchasesDAO.selectedCustomerRow}" 
    widgetVar="customerTableSearch" 
    filteredValue="#{purchasesDAO.filteredCustomerRow}" 
    selectionMode="single" value="#{purchasesDAO.customerList}" 
    style="font-size:10px;"> 

這是通過複製/粘貼代碼開發過程中造成的,缺少widgetVar線更新時代碼。將客戶數據表中的widgetVar更改爲不同於購買表解決了問題。

相關問題