gpt4 book ai didi

jsf - 为什么我的 JSF FacletContext==null?

转载 作者:行者123 更新时间:2023-12-04 04:48:39 26 4
gpt4 key购买 nike

我的 FaceletContext我试着相处

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

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

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

更新:

要更清楚。我有以下 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 绑定(bind)到一个 panelGroup :
<ui:fragment>
<h:panelGroup binding="#{groupComponentTreeBuilder.groupTree}" />
</ui:fragment>

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

有什么建议么?

最佳答案

问题是

FaceletContext.FACELET_CONTEXT_KEY

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

但我需要

javax.faces.FACELET_CONTEXT

谢谢垫:-)

关于jsf - 为什么我的 JSF FacletContext==null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17780922/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com