[英]Get id of parent naming container in template for in render / update attribute
我有一个模板,在其定义中我使用了几个表单和按钮。
问题是定义(定义)xhtml文件不知道组件层次结构。
例如,我想在同一个定义文件中以不同的形式更新元素“table2”。
模板插入:
<p:tabView id="nav"> <!-- nav -->
<ui:insert name="content_nav">content navigation</ui:insert>
</p:tabView>
定义我的层次结构“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>
在我的定义部分,我不想知道“导航”!
我怎样才能做到这一点? 或者如何向上移动一个命名组件?或者将最高父完整ID保存在变量中?
有时我看到类似的东西:
update=":table2"
但是我找不到任何关于这个的信息?,JavaEE 6文档只是提到@关键字。
丑陋,但这应该适合你:
<p:commandButton action="..." update=":#{component.namingContainer.parent.namingContainer.clientId}:form2:table2" />
由于您已经在使用PrimeFaces,另一种方法是使用#{p:component(componentId)}
,此帮助函数会扫描整个视图根目录以查找具有给定ID的组件,然后返回其客户端ID:
<p:commandButton action="..." update=":#{p:component('table2')}" />
丑陋的回答很有效
update=":#{component.namingContainer.parent.namingContainer.clientId}:form2:table2
主要是从打开的对话框更新到父数据表更有用
除了上面的解决方案,我遇到了问题,我必须基于服务器端逻辑动态生成要更新的组件(很多)(可能更难找到嵌套)。
因此,服务器端的解决方案相当于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
}
通过使用它的其他方法调用,例如... update="#{foo.getCompListComputed( 'triggeringCompId' )}"
。
1 :首先我试着没有太多想法返回public static String getCompListSpaced0() { return ":#{p:component('table2')}" ; }
public static String getCompListSpaced0() { return ":#{p:component('table2')}" ; }
在... update="#{foo.getCompListSpaced0()}
表达,这当然没有解决(想着怎么框架工程:)后)(返回为是),并用它可以引起问题的一些用户此外,我的Eclipse / JBoss Tools环境建议编写:#{p.component('table2')}
(“。”而不是“:”)当然没有帮助。
您可以使用binding
属性声明绑定到JSF组件的EL变量。 然后,您可以使用javax.faces.component.UIComponent.getClientId()
访问此组件的绝对客户端ID。 见下面的例子:
<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>
试试这个:
<h:commandButton value="Click me">
<f:ajax event="click" render="table" />
</h:commandButton>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.