2012-08-23 31 views
5

我有一個JSP 2.0 <ui:component>,其中是一個<p:dataTable>與一列使用複合呈現關於某些內容的特殊邊框。現在我需要確定位於內容中的ajax呈現屬性中的<p:dataTabe>如何訪問複合材料的父命名容器?

<ui:component> 
    <p:dataTable id="dataTable" var="userItem" ... /> 
    <p:column> 

     <my:borderBox id="borderBox"> 
      <p:commandButton 
       action="#{userController.doDelete(userItem.id)}" 
       value="delete" 
       update="?????"/> <!-- How to address the dateTable? --> 
     </my:borderBox> 

     </p:column> 
    </p:dataTable> 
<ui:component> 

我BorderBox:

<html xmlns:composite="http://java.sun.com/jsf/composite" ...> 
    <composite:interface> 
     <composite:attribute name="styleClass" default="" type="java.lang.String"/> 
    </composite:interface> 

    <composite:implementation> 
     <h:panelGroup ...> 
     ... 
     <composite:insertChildren/> 
     </h:panelGroup> 
    </composite:implementation> 

我的想法是使用類似

update=":#{component.namingContainer.parent.namingContainer.clientId}:dateTable

component.namingContainer.parent接縫爲空。

當我更換<p:commandButton>此聲明:

Parent ClientId 1: #{component} 
Parent ClientId 2: #{component.namingContainer} 
Parent ClientId 3: #{component.namingContainer.clientId} 

Parent ClientId 4: #{component.namingContainer.parent} 
Parent ClientId 5: #{component.namingContainer.parent.namingContainer} 

我得到這樣的輸出:

Parent ClientId 1: [email protected] 

Parent ClientId 2: [email protected] 
Parent ClientId 3: main_form:profilTabView:dataTable:0:borderBox 

Parent ClientId 4: 
Parent ClientId 5: 

我不知道什麼問題吧:mybey我的想法,以確定完成列表錯誤或有一些錯誤或有更好的方法? (但我不能用固定絕對identifyer爲dateTable!)

版本:Primeface 3.2,鑽嘴魚科2.1.6在Glassfish 3.1.2

+1

不幸的是我不使用'ui:component'標籤,所以我對它不瞭解太多;我通常使用複合組件,您可以從EL表達式中引用父命名容器,如'#{cc.parent.id}'。不過,我認爲'parent'是EL表達式語言中的一個保留變量,所以它應該像'#{parent.id}'一樣簡單,以檢索父命名容器標識符。 –

+0

@maple_shaft:''被複合組件隱式使用。因此,直接聲明而不是''更清晰。 – BalusC

+0

您正在使用哪個JSF impl /版本和PF版本? – BalusC

回答

1

我對這個問題的方法。如果您找不到其他解決方案,則可以將其用作替代方案。解決方案是jsf和javascript之間的混合。爲你的表定義一個小部件(例如「myTable」)。

<p:dataTable id="dataTable" var="userItem" ... widgetVar="myTable"/> 

這是一個名爲「myTable」的全局JavaScript變量被創建。這個小部件對象包含一個id。對於你的命令按鈕(H:沒有的commandButton號碼:的commandButton)定義onklick事件:

<h:commandButton id="deleteItem" action="#{userController.doDelete(userItem.id)}" 
value="delete" onclick="PrimeFaces.ab({formId:$(this).closest('form').attr('id'),source:this.id,process:'@all',update:myTable.id});return false;" /> 


formId - 你明確的形式輸入ID或使用我的jQuery函數
更新 - myTable.id是表ID(正好是div封裝)
process - @all,@ this,@form等..