2013-02-14 30 views
6

我遇到了p:dataTable問題,並且排除了單行選擇中的列。Primefaces:從p:dataTable中的行選擇中排除列

我在我的dataTable中有4列。前三個需要顯示fileId,fileName和uploadDate。在第4列中,每行都有一個命令按鈕,用於啓動文件處理操作。 但也有導航到文件詳細信息頁面的行選擇(對事件有ajax操作)。 現在,當我點擊行的任何地方(包括按鈕),它將我導航到詳細信息頁面。

有我當前的代碼:

<h:form> 
    <p:dataTable id="billingFiles" value="#{billingFiles}" 
     var="billingFile" 
     rowKey="#{billingFile.billingFile.idBillingFile}" 
     filteredValue="#{billingService.filteredBillingFileDataModels}" 
     selectionMode="single" paginator="true" rows="10"> 

     <p:ajax event="rowSelect" listener="#{billingService.selectBillingFileRow}" /> 

     <p:column sortBy="#{billingFile.id}" 
      filterBy="#{billingFile.id}" id="idFile" 
      headerText="#{msg['billing.file.id']}" 
      filterMatchMode="contains"> 
      <h:outputText value="#{billingFile.id}" /> 
     </p:column> 

     <p:column sortBy="#{billingFile.uploadDate}" 
      filterBy="#{billingFile.uploadDate}" id="uploadDate" 
      headerText="#{msg['billing.file.upload_date']}" 
      filterMatchMode="contains"> 
      <h:outputText value="#{billingFile.uploadDate}" /> 
     </p:column> 

     <p:column sortBy="#{billingFile.fileName}" 
      filterBy="#{billingFile.fileName}" id="fileName" 
      headerText="#{msg['billing.file.file_name']}" 
      filterMatchMode="contains"> 
      <h:outputText value="#{billingFile.fileName}" /> 
     </p:column> 

     <p:column id="loadBillingFile"> 
      <p:commandButton id="loadBillingFileButton" 
       rendered="#{billingFile.fileStatus.equals('UPLOADED')}" 
       value="#{msg['billing.load_billing_file']}" 
       action="#{billingService.loadBillingFile(billingFile.billingFile)}" 
       update=":form" /> 
     </p:column> 
    </p:dataTable> 
</h:form> 

而且還有導航到文件的詳細信息頁面的方法:

public void selectBillingFileRow(SelectEvent event) { 
    BillingFileDataModel billingFileDataModel = (BillingFileDataModel) event.getObject(); 
    if (billingFileDataModel != null) { 
     selectedBillingFile = billingFileDAO.findBillingFileById(billingFileDataModel.getBillingFile().getIdBillingFile()); 
     FacesContext.getCurrentInstance().getExternalContext() 
     .getRequestMap().put(JsfView.EVENT_KEY, "viewBillingFile"); 
    } 
} 

有沒有辦法與來自行選擇按鈕排除列?我只需要它開始處理文件,而無需將我導航到其他頁面。

+0

你處理什麼文件,它是一個數據庫? – 2013-02-14 16:21:55

+0

它開始用Spring Batch處理txt文件。 – Rozart 2013-02-14 16:23:30

+1

你有一個rowSelect Primefaces Ajax事件上的dataTable執行下面的監聽器,每當你點擊一行:''{{billingService.selectBillingFileRow}「'我會看在這個方法的代碼,看看它是重定向還是轉發頁。 – 2013-02-14 16:48:26

回答

4

我發現我的問題的部分解決方案。 當onClick事件發生時,我阻止了rowSelect ajax動作的執行。

我加入這行p:commandButton

onclick="event.stopPropagation();" 

我說,它的工作原理部分,因爲點擊列與按鈕,而不是按鈕本身,還是執行rowSelect行動。

+0

另一個粗糙的選項是有選擇地從getComponent()中獲取SelectEvent的源,並根據觸發事件的組件的類型有選擇地執行方法體的其餘部分 – kolossus 2013-02-15 14:27:14