2016-07-21 58 views
0

我想更新primefaces數據表標題facet中的按鈕,但它不起作用。我複製數據表外的按鈕一切工作正常。f:facet name =「header」中的Primefaces數據表更新不起作用

當數據表的過濾器事件被觸發時,應該發生更新。我明確地更新了數據表,外部和內部按鈕。

其意圖是在未設置過濾器時顯示帶有圖標的按鈕,並且在使用過濾器時顯示帶有另一個圖標的按鈕。在這個例子中,我簡單介紹了用例:如果沒有過濾器被使用,就會有一個開鎖圖標,如果我在過濾器中鍵入某個東西,應該顯示一個閉鎖圖標。要釋放鎖,必須點擊按鈕(我沒有實現刪除數據表中的過濾器)。

從我的理解我使用標題內的按鈕的正確ID。所以我不知道爲什麼這不起作用?

我使用鑽嘴魚科2.2和primefaces 6.

<h:form id="id_form"> 
    <p:dataTable 
     id="id_table" 
     value="#{stateController.names}" 
     var="currentName"> 

     <p:ajax 
      event="filter" 
      listener="#{stateController.markLocked()}" 
      update="id_table id_form:id_table:id_button_inside id_form:id_button_outside"/> 

     <p:column 
      filterBy="#{currentName}" 
      filterMatchMode="contains"> 
      <f:facet name="header"> 
       <p:commandButton 
        id="id_button_inside" 
        action="#{stateController.markUnlocked()}" 
        icon="#{stateController.locked ? 'ui-icon-locked' : 'ui-icon-unlocked'}" 
        update="id_form"/> 
      </f:facet> 
      <h:outputText value="#{currentName}" /> 
     </p:column> 
    </p:dataTable> 

    <p:commandButton 
     id="id_button_outside" 
     action="#{stateController.markUnlocked()}" 
     icon="#{stateController.locked ? 'ui-icon-locked' : 'ui-icon-unlocked'}" 
     update="id_form" 
     /> 
</h:form> 

我還試圖把一個按鈕在單獨的列。有了這個按鈕(它顯示在數據表的每一行),一切工作正常。

+0

嘗試包裹在'按鈕<號碼:outputPanel ID = 「包裝」>'和更新:' Artem

+0

嗨@Artem,對於遲到的回答感到抱歉。我在按鈕周圍的''試了一下,但是和沒有面板的結果是一樣的:-( – Filou

回答

2

這有點晚,但也許有人會發現有用的一天。

要解決Filou的問題,您需要在dataTable之外定義remoteCommand並使其更新dataTable的標題facet。

<p:remoteCommand name="rmtCommand" update="id_form:id_table:id_button_inside"/> 
<p:dataTable 
    id="id_table" 
    value="#{stateController.names}" 
    var="currentName"> 

    <p:ajax 
     event="filter" 
     listener="#{stateController.markLocked()}" 
     oncomplete="rmtCommand()"/>