2

FaceletContext试着相处

FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);

总是null。这里出了什么问题?

实际上我尝试做的是从bean动态添加一个复合组件。

更新:

要更清楚。我有以下豆:

@Named
@SessionScoped
public class GroupComponentTreeBuilder implements Serializable {

public UIComponent getGroupTree() {

    UIComponent parent1 = UIComponent.getCurrentComponent(FacesContext.getCurrentInstance());

    return includeCompositeComponent(parent1, "group", "elementgroup.xhtml", "myNewSuperId");
}

public static UIComponent includeCompositeComponent(UIComponent parent, String libraryName, String resourceName, String id) {
    FacesContext context = Faces.getContext();
    Application application = context.getApplication();

    FaceletContext faceletContext = Faces.getFaceletContext();

    Resource resource = application.getResourceHandler().createResource(resourceName, libraryName);
    UIComponent composite = application.createComponent(context, resource);
    composite.setId(id);

    UIComponent implementation = application.createComponent(UIPanel.COMPONENT_TYPE);
    implementation.setRendererType("javax.faces.Group");
    composite.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, implementation);

    parent.getChildren().add(composite);
    parent.pushComponentToEL(context, composite); // This makes #{cc}
                                                    // available.
    try {
        faceletContext.includeFacelet(implementation, resource.getURL());
    } catch (IOException e) {
        throw new FacesException(e);
    } finally {
        parent.popComponentFromEL(context);
    }

    return composite;
}
}

我想将加载的 bean 绑定到一个 panelGroup :

<ui:fragment>
    <h:panelGroup binding="#{groupComponentTreeBuilder.groupTree}" />
</ui:fragment>

问题是 FacletContext 为空,所以我不能调用 includerFacelet()。

有什么建议么?

4

1 回答 1

3

问题是

FaceletContext.FACELET_CONTEXT_KEY

返回了错误的字符串键“com.sun.faces.facelets.FACELET_CONTEXT”

但我需要

javax.faces.FACELET_CONTEXT

谢谢垫:-)

于 2013-07-22T12:25:44.877 回答