How to pass the node value as the attribute in Composite Component in JSF 2.0

家住魔仙堡 提交于 2019-12-02 06:14:14

问题


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

Some thing like..

<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 attribute "value", like so:

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

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


回答1:


You aren't passing it as tag attribute. You are just passing it as child in the tag body. In that case you need to use <composite:insertChildren /> to insert it. So, instead of

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

you should be doing

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

Or if you actually want to use #{cc.attrs.value}, then you should be defining it as a real tag attribute from the beginning on instead of as tag body:

<someDir:boxComp value="Hello" />


来源:https://stackoverflow.com/questions/5090574/how-to-pass-the-node-value-as-the-attribute-in-composite-component-in-jsf-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!