Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF2: ui:include: Component ID must be unique

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" />
like image 381
Michael Bavin Avatar asked Aug 09 '10 14:08

Michael Bavin


1 Answers

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

like image 180
Maxim Manco Avatar answered Sep 21 '22 01:09

Maxim Manco