JSF 1.2 自定义组件不会渲染/编码子组件

标签 jsf custom-component jsf-1.2

我有两个自定义组件:

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

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

最佳答案

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

This method will only be called if the rendersChildren property is true.

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

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

关于JSF 1.2 自定义组件不会渲染/编码子组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12052195/

相关文章:

jsf - 如何强制 tomEE 使用 mojarra?

java - 如何将 JScrollbar 的 Thumb 更改为自定义图像

java - Jsf表单打印预览

Java Swing 自定义控件

delphi - 制作包含其他组件的自定义组件的正确方法

jsf - 为可重用 JSF 弹出窗口中的有条件禁用字段提交空值

xpages - 是否有相当于 JSF <ui :debug/> tag? 的 XPages

java - 冰脸旋转监听器?

jsf - 显示开/关 HTML 的不同区域

templates - 模板中的多个 primefaces 消息