Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get id of parent naming container in template for in render / update attribute

I have a template and in its Definition I use several forms and buttons.

The problem is the definition (define) xhtml file does not know the component hierarchy.

And for example I want to update the element "table2" in a different form in the same define file.

Template Insert:

<p:tabView id="nav"> <!-- nav -->
    <ui:insert name="content_nav">content navigation</ui:insert>
</p:tabView>

defines the first level of my hierarchy "nav"

Template define:

<ui:define name="content_nav">
    <h:form id="form1"> <!-- nav:form1 -->
        <h:dataTable id="table1"/> <!-- nav:form1:table1 -->
        <p:inputText value="#{bean.value}"/>
        <p:commandButton action="..." update="nav:form2:table2"/>
    </h:form>
    <h:form id="form2">
        <h:dataTable id="table2"/> <!-- nav:form2:table2 -->
        <!-- other elements -->
    </h:form>
</ui:define>

In my define part I don't want to know "nav"!

How can I do this? or how can I move one naming component upwards?, or save the highest parent complete id in a variable?

sometimes i saw something like:

update=":table2"

But I could not find any informations about this?, the JavaEE 6 documentation just mentions the @ keywords.

like image 393
djmj Avatar asked Jan 13 '12 07:01

djmj


3 Answers

Ugly, but this should work out for you:

<p:commandButton action="..." update=":#{component.namingContainer.parent.namingContainer.clientId}:form2:table2" />

As you're already using PrimeFaces, an alternative is to use #{p:component(componentId)}, this helper function scans the entire view root for a component with the given ID and then returns its client ID:

<p:commandButton action="..." update=":#{p:component('table2')}" />
like image 68
BalusC Avatar answered Nov 14 '22 09:11

BalusC


ugly answer works well

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

mainly more useful updating from opened dialog to parent datatable

like image 32
user2120191 Avatar answered Nov 14 '22 11:11

user2120191


You may use binding attribute to declare EL variable bound to JSF component. Then you may access absolute client id of this component by using javax.faces.component.UIComponent.getClientId(). See example below:

<t:selectOneRadio 
   id="yourId"
   layout="spread"
   value="#{yourBean.value}"
   binding="#{yourIdComponent}">
       <f:selectItems value="#{someBean.values}" />
</t:selectOneRadio>
<h:outputText>
   <t:radio for=":#{yourIdComponent.clientId}" index="0" />
</h:outputText>
like image 1
Dmitry Trifonov Avatar answered Nov 14 '22 09:11

Dmitry Trifonov