Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
980 views
in Technique[技术] by (71.8m points)

jsf 2 - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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')}" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...