JSF2: ui:include: Component ID must be unique
Asked Answered
H

1

5

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"/>
....
<!-- 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" />
Hannahannah answered 9/8, 2010 at 14:25 Comment(2)
where do you want to refer it? I mean are you trying yo refer it from javascript?Gecko
I'm using primefaces, and i want to use the "update" attribute of an ajax call from a button. That attribute needs the clientId as a value. I'm trying to make this topic not primefaces specific.Hannahannah
P
10

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

Policyholder answered 9/8, 2010 at 14:36 Comment(1)
Thanx for your answer! Altough i need extra logic for this as my ui:include list is variable...Hannahannah

© 2022 - 2024 — McMap. All rights reserved.