My FaceletContext
I try to get with
FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
is always null
. What is going wrong here?
Actually what I try to do is to add a composite component dynamically from bean.
Update:
To be more clear. I have the following 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;
}
}
And I want to bind the loaded bean to a panelGroup :
<ui:fragment>
<h:panelGroup binding="#{groupComponentTreeBuilder.groupTree}" />
</ui:fragment>
The problem is that the FacletContext is null, so i can not call includerFacelet ().
Any suggestions?