2

I have two custom components:

CustomUIComponent extends UIComponentBase
CustomChildUIComponent extends UIComponentBase

In CustomUIComponent I implement encodeBegin, encodeChildren and encodeEnd - in encodeChildren I set some custom attribute to be forwarded to the child component.

In CustomChildUIComponent I implement only encodeBegin.

In addition to these classes I added the components in the faces-config.xml:

<component>
    <component-type>test.JsfMessage</component-type>
    <component-class>test.CustomUIComponent</component-class>
</component>
<component>
     <component-type>test.JsfChildMessage</component-type>
     <component-class>test.CustomChildUIComponent</component-class>
</component>

And I have the custom taglib.xml configured in the web.xml and contains:

<tag>
    <tag-name>customMessage</tag-name>
    <component>
        <component-type>test.JsfMessage</component-type>
    </component>
</tag>

<tag>
    <tag-name>customChildMessage</tag-name>
    <component>
        <component-type>test.JsfChildMessage</component-type>
    </component>
</tag>

Finally in my Facelets page I am trying to execute:

<myns:customMessage message="Hello World!!!" var="mytestvar">
    <myns:customChildMessage partnermsg="#{mytestvar}" />
</myns:customMessage>

The result is that the parent is rendered but the child component does not.

Am I doing something wrong?

I tried checking the super.encodeChildren but it checks:

Renderer renderer = getRenderer(context);
if(renderer != null) ...

I am not using a renderer class, but as I understand it is not a must.

4

1 回答 1

2

只有当同一个自定义组件的方法返回时,才会encodeChildren()调用自定义组件的方法。这是在javadoc中指定的:getRendersChildren()true

rendersChildren仅当属性为时才会调用此方法true

因此,请确保您已相应地覆盖它,即默认为false

@Override
public boolean getRendersChildren() {
    return true;
}
于 2012-08-24T17:03:48.433 回答