Jsf 自定义组件赢得';不显示嵌套组件

Jsf 自定义组件赢得';不显示嵌套组件,jsf,xpages,custom-component,Jsf,Xpages,Custom Component,我写的自定义组件有问题,因为它不会呈现任何嵌套控件。该组件是一个简单的布局控件,非常松散地改编自扩展库中的ApplicationLayout控件。XPage代码如下所示: <px:exampleControl id="exampleControl1"> <xp:span styleClass="mySpan">Inner Text</xp:span> </px:exampleControl> package com.example

我写的自定义组件有问题,因为它不会呈现任何嵌套控件。该组件是一个简单的布局控件,非常松散地改编自扩展库中的ApplicationLayout控件。XPage代码如下所示:

<px:exampleControl id="exampleControl1">    
    <xp:span styleClass="mySpan">Inner Text</xp:span>
</px:exampleControl>
package com.example.component;

import javax.faces.FacesException;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;

import com.ibm.xsp.component.FacesComponent;
import com.ibm.xsp.page.FacesComponentBuilder;

public class CustomLayout extends UIComponentBase implements FacesComponent {

public CustomLayout(){
    super();
    setRendererType("com.example.applicationlayout");
}

@Override
public String getFamily() {
    return "com.example.applicationlayout";
}

public void buildContents(FacesContext context, FacesComponentBuilder builder)
        throws FacesException {     
    builder.buildAll(context, this, true);
}

public void initAfterContents(FacesContext context) throws FacesException {

}

public void initBeforeContents(FacesContext context) throws FacesException      

}
}
我甚至尝试使用从扩展库渲染器(AbstractApplicationLayoutRenderer.java中的实用程序函数)借用的特定渲染函数,但component.getChildCount()始终返回0


那么为什么嵌套控件不呈现,我缺少什么呢?

我终于找到了答案。渲染器代码有点刺耳,因为正如Stephan(stwissel)评论的那样,Renderer.encodeChildren什么都不做。查看几个ExtLib组件的源代码,没有一个使用它

我所做的改变是扩展类。在阅读Keith Strickland的博客()并检查com.ibm.xsp.extlib.component.layout.UIVarPublisherBase之后,我实现了FacesComponent接口。特别是,我想调用调用FacesComponentBuilder的buildContents方法。JavaDoc for FacesComponent对FacesComponent有这样的描述:

buildContents构建组件子级和方面,默认实现通常是:builder.buildAll(context,this,true);//includeFacets=true

我的扩展课程最终是这样的:

<px:exampleControl id="exampleControl1">    
    <xp:span styleClass="mySpan">Inner Text</xp:span>
</px:exampleControl>
package com.example.component;

import javax.faces.FacesException;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;

import com.ibm.xsp.component.FacesComponent;
import com.ibm.xsp.page.FacesComponentBuilder;

public class CustomLayout extends UIComponentBase implements FacesComponent {

public CustomLayout(){
    super();
    setRendererType("com.example.applicationlayout");
}

@Override
public String getFamily() {
    return "com.example.applicationlayout";
}

public void buildContents(FacesContext context, FacesComponentBuilder builder)
        throws FacesException {     
    builder.buildAll(context, this, true);
}

public void initAfterContents(FacesContext context) throws FacesException {

}

public void initBeforeContents(FacesContext context) throws FacesException      

}
}
它现在似乎像我想要的那样工作


另外,ExtLib中的其他对象(特别是UIWidgetContainer和UIList)在不实现FacesComponent的情况下有不同的方式呈现其子对象。这可能需要一篇博文。

您是否检查了Renderer.encodeChildren?AFAIK它什么都不做——这就是为什么你需要覆盖它,所以对“super”的调用什么都不做。至少你需要设置rendersChildren,很高兴你找到了答案,我也能帮上忙。我试图回答早些时候,但有身份验证问题。