【问题标题】:JSF2: ui:include: Component ID must be uniqueJSF2: ui:include: 组件 ID 必须是唯一的
【发布时间】:2011-03-27 08:09:40
【问题描述】:

基本问题:

包括一个页面,其中包含一个具有组件 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" />

【问题讨论】:

  • 你想在哪里引用它?我的意思是你想从 javascript 中引用它吗?
  • 我正在使用 primefaces,并且我想使用按钮的 ajax 调用的“更新”属性。该属性需要 clientId 作为值。我试图让这个主题不是特定的primefaces。

标签: java jsf facelets jsf-2


【解决方案1】:

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

【讨论】:

  • 感谢您的回答!尽管我需要额外的逻辑,因为我的 ui:include 列表是可变的......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-20
  • 2012-05-12
  • 1970-01-01
  • 1970-01-01
  • 2012-03-16
相关资源
最近更新 更多