Search code examples
jsf-2composite-component

Passing f:atrribute to a nested composition component


I have two nested composite components such as:

<my:inputContainer>
    <my:input/>
</my:inputContainer>

And I need to pass a f:attribute to my:input in order to get it back in its validator:

<my:inputContainer>
    <my:input>
        <f:attribute name="attr" value="any value"/>
    </my:input>
</my:inputConainer>

But when I try to retrieve the attribute value in validator from component.getAttributes() it doesn't exist.

My components are defined basically this way:

<cc:implementation>
    <my:input name="input1"/>
    <my:input name="input2">
        <f:attribute name="input1Value" value="#{cc.attrs.input1Value}"/>
        <f:validator validatorId="myInputValidator" for="inputText"/>      
    </my:input>
</cc:implementation>

Any help will be appreciated.


Solution

  • I realized that's not possible. cc:insertChildren does not render f:attribute. If you want to pass a f:attribute from one component to another, you must define cc:attribute in cc:interface.

    ComponentA

    ...
    <cc:implentation>
       <my:componentB>
            <f:attribute name="myAttr" value="The attribute value"/>
       </my:componentB>
    </cc:implementation>
    

    ComponentB

    <cc:interface>
        ...
        <cc:attribute name="myAttr"/>
    </cc:attribute>
    
    <cc:implementation>
        <my:input name="input1"/>
        <my:input name="input2">
            <f:attribute name="input1Value" value="#{cc.attrs.myAttr}"/>
            <f:validator validatorId="myInputValidator" for="inputText"/>      
        </my:input>
    </cc:implementation>