【问题标题】:JSF 1.2 custom component does not render/encode childrenJSF 1.2 自定义组件不渲染/编码子组件
【发布时间】:2012-08-16 15:23:22
【问题描述】:

我有两个自定义组件:

CustomUIComponent extends UIComponentBase
CustomChildUIComponent extends UIComponentBase

在 CustomUIComponent 中我实现了 encodeBegin、encodeChildren 和 encodeEnd - 在 encodeChildren 中我设置了一些自定义属性以转发给子组件。

在 CustomChildUIComponent 中,我只实现了 encodeBegin。

除了这些类之外,我还在 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>

我在 web.xml 中配置了自定义 taglib.xml 并包含:

<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>

最后在我尝试执行的 Facelets 页面中:

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

结果是父组件被渲染,而子组件没有。

我做错了吗?

我尝试检查 super.encodeChildren 但它检查:

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

我没有使用渲染器类,但据我了解,这不是必须的。

【问题讨论】:

    标签: jsf custom-component jsf-1.2


    【解决方案1】:

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

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

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

    @Override
    public boolean getRendersChildren() {
        return true;
    }
    

    【讨论】:

    • 您好,谢谢您的回复,很抱歉回复晚了:) 我在代码中确实有这个被覆盖的方法,但它仍然不起作用......
    猜你喜欢
    • 2011-03-17
    • 1970-01-01
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    • 2011-03-06
    • 1970-01-01
    • 2012-04-26
    相关资源
    最近更新 更多