Awano
Awano

Reputation: 171

Can we use ui:include in JSF to display a component?

I am new to JSF and I am trying to display a JSF2 component with ui:include

<ui:include src="myComponent.xhtml">
    <ui:param name="attr" value="aValue"/>
</ui:include>

The component is successfully displayed but the param is not passed to the JSF2 component. the attribute attr is defined in the interface of the component.

It works if I use my component this way:

<ez:myComponent attr="aValue"/>

The point in using ui:include is to use something like that:

<ui:include src="#{componentName}"/>

Am I doing something that is not supported or is there another way to display my component and have the parameters filled?

I am using GlassFish v3.

Thanks in advance.

Upvotes: 2

Views: 4954

Answers (2)

Adam
Adam

Reputation: 3795

Based on the comments in Inv3r53's answer: Periods have a special meaning in expression language to evaluate chains of expressions. If you want your page to be both standalone and used as a component then use a c:set (JSF 2 doc) outside of your composition tags to set cc.attrs.attr to attr. The set will be used if standalone, but left out when included (only the stuff between the composition tags is included).

Upvotes: 0

Inv3r53
Inv3r53

Reputation: 2969

from my understanding of ui:param you should be able to acess the value of the ui:param in myComponent.xhtml by using #{attr} which by using param name check this out https://facelets.dev.java.net/nonav/docs/dev/docbook.html#template-param

Upvotes: 1

Related Questions