在模板中获取父命名容器的 id 以用于渲染/更新属性 [英] Get id of parent naming container in template for in render / update attribute

查看:11
本文介绍了在模板中获取父命名容器的 id 以用于渲染/更新属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模板,在它的定义中我使用了几个表单和按钮.

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

问题是定义(define)的xhtml文件不知道组件层次结构.

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

例如,我想在同一个定义文件中以不同的形式更新元素table2".

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

模板插入:

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

定义我的层次结构导航"的第一级

defines the first level of my hierarchy "nav"

模板定义:

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

我该怎么做?或者如何将一个命名组件向上移动?或将最高的父完整 ID 保存在变量中?

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"

但我找不到有关此的任何信息?JavaEE 6 文档只提到了@ 关键字.

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

推荐答案

丑陋,但这应该适合你:

Ugly, but this should work out for you:

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

由于您已经在使用 PrimeFaces,另一种方法是使用 #{p:component(componentId)},此辅助函数会扫描具有给定 ID 的组件的整个视图根,然后返回其客户端 ID:

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

这篇关于在模板中获取父命名容器的 id 以用于渲染/更新属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆