2010-08-09 87 views
2

基本问题:JSF2:ui:include:组件ID必须是唯一的

包含一个包含组件ID的组件的页面,多次无法完成。但我如何能够引用该组件包含页面?

实施例:

included.xhtml

.... 
<h:form id="foo"/> 
.... 
<!-- here i need reference to foo component of this page --> 

的index.xhtml

.... 
<ui:include src="included.xhtml" /> 
<ui:include src="included.xhtml" /> 
<ui:include src="included.xhtml" /> 
+0

在哪里你想参考吗? 我的意思是你想你从JavaScript引用它? – 2010-08-09 14:29:28

+0

我正在使用primefaces,我想使用按钮的ajax调用的“更新”属性。该属性需要clientId作为值。我试图让这个主题不是特定于表面的。 – 2010-08-09 14:35:37

回答

8

随着ui:include的ID将被复制。

您可以将参数传递给您的包括XHTML和前缀您的ID

<ui:include src="included.xhtml"> 
    <ui:param name="idPrefix" value="myFormIdPrefix"/> 
</ui:include> 

在附带XHTML

<h:form id="#{idPrefix}_foo"/> 

现在就可以在引用该id为#{idPrefix}_foo

+0

Thanx为您的答案!尽管我需要额外的逻辑作为我的用户界面:包含列表是可变的... – 2010-08-09 14:40:02

+0

+1好玩的技巧知道 – ewernli 2010-08-09 16:41:39

相关问题