How to pass node value as attribute in composite component in JSF 2.0

I am developing a composite component of JSF 2.0. I am trying to create a box component in which my required HTML will be set as an attribute.

Sort of..

<composite:interface>
    <composite:attribute name="value" />
</composite:interface>
<composite:implementation>
    <table cellpadding="0" cellspacing="0" border="1" width="100%">
        <tr>
            <td></td>
            <td>#{cc.attrs.value}</td>
            <td></td>
        </tr>
    </table>
</composite:implementation>

When I want to use this component and pass the required HTML to the value attribute, for example:

<someDir:boxComp>Hello</someDir:boxComp>

Hello is not taken as an attribute value. How can I make the node value as an attribute value.?

+2
source share
1 answer

You do not pass it as an attribute of a tag. You just pass it as a child of the tag. In this case, you need to use <composite:insertChildren />to insert it. So instead

<td>#{cc.attrs.value}</td>

you have to do

<td><composite:insertChildren /></td>

, #{cc.attrs.value}, , :

<someDir:boxComp value="Hello" />
+2

All Articles