[英]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. 问题是定义(定义)xhtml文件不知道组件层次结构。
And for example I want to update the element "table2" in a different form in the same define file. 例如,我想在同一个定义文件中以不同的形式更新元素“table2”。
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" 定义我的层次结构“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?
或者如何向上移动一个命名组件?或者将最高父完整ID保存在变量中?
sometimes i saw something like: 有时我看到类似的东西:
update=":table2"
But I could not find any informations about this?, the JavaEE 6 documentation just mentions the @ keywords. 但是我找不到任何关于这个的信息?,JavaEE 6文档只是提到@关键字。
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: 由于您已经在使用PrimeFaces,另一种方法是使用
#{p:component(componentId)}
,此帮助函数会扫描整个视图根目录以查找具有给定ID的组件,然后返回其客户端ID:
<p:commandButton action="..." update=":#{p:component('table2')}" />
ugly answer works well 丑陋的回答很有效
update=":#{component.namingContainer.parent.namingContainer.clientId}:form2:table2
mainly more useful updating from opened dialog to parent datatable 主要是从打开的对话框更新到父数据表更有用
Additionally to the solutions above I had the problem, that I had to dynamically generate the to-be-updated components (many) based on server-side logic (with maybe harder to find out nesting). 除了上面的解决方案,我遇到了问题,我必须基于服务器端逻辑动态生成要更新的组件(很多)(可能更难找到嵌套)。
So the solution on the server-side is an equivalent to update=":#{p:component('table2')}"
1 which uses org.primefaces.util.ComponentUtils.findComponentClientId( String designId )
: 因此,服务器端的解决方案相当于
update=":#{p:component('table2')}"
1 ,它使用org.primefaces.util.ComponentUtils.findComponentClientId( String designId )
:
// UiPnlSubId is an enum containing all the ids used within the webapp xhtml.
// It could easily be substituted by a string list or similar.
public static String getCompListSpaced( List< UiPnlSubId > compIds ) {
if ( compIds == null || compIds.isEmpty() )
return "" ;
StringBuffer sb = new StringBuffer( ":" ) ;
for ( UiPnlSubId cid : compIds )
sb.append( ComponentUtils.findComponentClientId( cid.name() ) ).append( " " ) ;
return sb.deleteCharAt( sb.length() - 1 ).toString() ; // delete suffixed space
}
called via some other method using it, eg like ... update="#{foo.getCompListComputed( 'triggeringCompId' )}"
. 通过使用它的其他方法调用,例如
... update="#{foo.getCompListComputed( 'triggeringCompId' )}"
。
1 : first I tried without too much thinking to return public static String getCompListSpaced0() { return ":#{p:component('table2')}" ; }
1 :首先我试着没有太多想法返回
public static String getCompListSpaced0() { return ":#{p:component('table2')}" ; }
public static String getCompListSpaced0() { return ":#{p:component('table2')}" ; }
in an ... update="#{foo.getCompListSpaced0()}
expression, which of course (after thinking about how the framework works :) ) is not resolved (returned as is) and may cause the issues with it some users experienced. Also my Eclipse / JBoss Tools environment suggested to write :#{p.component('table2')}
("." instead of ":") which did not help - of course. public static String getCompListSpaced0() { return ":#{p:component('table2')}" ; }
在... update="#{foo.getCompListSpaced0()}
表达,这当然没有解决(想着怎么框架工程:)后)(返回为是),并用它可以引起问题的一些用户此外,我的Eclipse / JBoss Tools环境建议编写:#{p.component('table2')}
(“。”而不是“:”)当然没有帮助。
You may use binding
attribute to declare EL variable bound to JSF component. 您可以使用
binding
属性声明绑定到JSF组件的EL变量。 Then you may access absolute client id of this component by using javax.faces.component.UIComponent.getClientId()
. 然后,您可以使用
javax.faces.component.UIComponent.getClientId()
访问此组件的绝对客户端ID。 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>
Try this: 试试这个:
<h:commandButton value="Click me">
<f:ajax event="click" render="table" />
</h:commandButton>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.