gpt4 book ai didi

jsf-2 - 在渲染/更新属性的模板中获取父命名容器的 ID

转载 作者:行者123 更新时间:2023-12-03 13:41:30 25 4
gpt4 key购买 nike

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

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

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

模板插入:

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

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

模板定义:
<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>

在我的定义部分,我不想知道“导航”!

我怎样才能做到这一点?或者我怎样才能向上移动一个命名组件?或者将最高父级完整 ID 保存在一个变量中?

有时我看到类似的东西:
update=":table2"

但是我找不到任何关于这个的信息?JavaEE 6 文档只提到了 @ 关键字。

最佳答案

丑陋,但这应该适合你:

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

由于您已经在使用 PrimeFaces,另一种方法是使用 #{p:component(componentId)} ,这个辅助函数扫描整个 View 根以查找具有给定 ID 的组件,然后返回其客户端 ID:
<p:commandButton action="..." update=":#{p:component('table2')}" />

关于jsf-2 - 在渲染/更新属性的模板中获取父命名容器的 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8847096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com