Search code examples
jsfjsf-2faceletscomposite-component

Assigning a parameter in a JSF composite component


I'm trying to figure out if it's possible to pass values into a backing bean via a JSF composite component. So if I have an interface like this

<composite:interface>
    <composite:attribute name="commentList"/>
</composite:interface>

Can I then assign the value of commentList to a backing bean to do some processing on it?

Bonus question: Can I create a bean localized to this component? Ie, is there a way to create a bean such that it doesn't conflict with other instance of this components?


Solution

  • You can have a so-called backing component which you bind via componentType attribute:

    <composite:interface componentType="someComposite">
    

    With

    @FacesComponent("someComposite")
    public class SomeComposite extends UINamingContainer {
        // ...
    }
    

    Yes, each composite instance will obviously have its own backing component instance.

    Here are some more concrete real world examples: