How to access the parent Naming Container of Composite?

一世执手 提交于 2019-12-30 06:49:17

问题


I have a JSP 2.0 <ui:component>, within that is a <p:dataTable> with a column that uses a Composite to render a special border about some content. Now I need to identify the <p:dataTabe> in a ajax rendered attribute that is located in the content.

<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>

My 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>

My idea was to use something like

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

But component.namingContainer.parent seams to be null.

When I replace the <p:commandButton> with this statements:

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}

I get this output:

Parent ClientId 1: javax.faces.component.html.HtmlPanelGroup@3d957419

Parent ClientId 2: javax.faces.component.UINamingContainer@23db9e8f
Parent ClientId 3: main_form:profilTabView:dataTable:0:borderBox

Parent ClientId 4:
Parent ClientId 5: 

I have no idea what the problem it: mybey my idea to identify the list is complete wrong or there some mistake or there is a better way? (But I can not use fix absolute identifyer for the dateTable!)

Versions: Primeface 3.2, Mojarra 2.1.6 on Glassfish 3.1.2


回答1:


I have a workaround for this Problem. If you can not find another solution, you can use it as an alternative. The Solution is a mix between jsf and javascript. For your table you define a widget (e.g. "myTable").

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

It is a global javascript variable named "myTable" is created. this widget object contains an id. For you command button (h:commandButton not p:commandButton) you define onklick event:

<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 - you enter the form ID explicitly or use my Jquery function
update - myTable.id is a Table ID (exactly div wrapper)
process - @all, @this, @form etc..



来源:https://stackoverflow.com/questions/12090950/how-to-access-the-parent-naming-container-of-composite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!