开发者

JSF2: ui:include: Component ID must be unique

开发者 https://www.devze.com 2023-01-10 15:54 出处:网络
Basic question: Including a page, that contains a component with component id, multiple times cannot be done. But how can i have a reference to that component iside that included page?

Basic question:

Including a page, that contains a component with component id, multiple times cannot be done. But how can i have a reference to that component iside that included page?

Example:

included.xhtml

....
<h:form id="foo"/>
....
<开发者_JAVA百科!-- 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" />


With ui:include the id will be duplicated.

You can pass a parameter to your included xhtml and prefix your id

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

In the included xhtml

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

Now it is possible to reference the id as #{idPrefix}_foo

0

精彩评论

暂无评论...
验证码 换一张
取 消