我有两个自定义组件:
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 istrue
.
因此,请确保您已相应地覆盖它,即默认为 false
:
@Override
public boolean getRendersChildren() {
return true;
}
关于JSF 1.2 自定义组件不会渲染/编码子组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12052195/