Search code examples
jsfjsf-2faceletscomposite-component

JSF 2.0: Passing composite component attribute to inner composite component


I have the following case:

<cc:interface>
    <cc:attribute name="someValue" />
</cc:interface>

<cc:composite>
    <x:someComponent>
        <span>#{cc.attrs.someValue}</span>
    </x:someComponent>
</cc:composite>

So inside my composite component I am calling some other composite component and trying to pass the parameter given to the "master" composite component to the inner composite component.

This fails, because inside x:someComponent tags the cc implicit object seems to refer to this x:someComponent instead.

A workaround is to create a temporary field for the x:someComponent so this can be achieved as:

<x:someComponent passthroughField="#{cc.attrs.someValue}">
    <span>#{cc.attrs.passthroughField}</span>
</x:someComponent>

However that's very ugly and unconvenient.

Any other ways around this problem?


Solution

  • One way to hack around this is to use ui:param as in:

    <ui:param name="foo" value="cc.attrs.someValue" />
    <x:someComponent>
        <span>#{foo}</span>
    </x:someComponent>
    

    See more in another question.