webtier@glassfish.java.net

Re: JSF 2 adding a composite components to the view from a managed bean?

From: <webtier_at_javadesktop.org>
Date: Mon, 06 Jul 2009 01:11:17 PDT

The following snippet kind of does what I want.

[code]
UIComponent viewPanel = getContext()
  .getViewRoot()
  .findComponent("form:viewPanel");

viewPanel.getChildren().clear();

Resource componentResource = getApplication()
  .getResourceHandler()
  .createResource("custom.xhtml","components/custom");
                
FacesContext context = getContext();
UIComponent composite = context.getApplication().createComponent(context, componentResource);

UIComponent compositeRoot = getApplication().createComponent(UIPanel.COMPONENT_TYPE);
composite.getAttributes().put(Resource.COMPONENT_RESOURCE_KEY, componentResource);
compositeRoot.setRendererType("javax.faces.Group");

try {
    FaceletFactory factory = (FaceletFactory)
    RequestStateManager.get(context, RequestStateManager.FACELET_FACTORY);
    Facelet f = factory.getFacelet(componentResource.getURL());
    f.apply(context, compositeRoot);
}
catch (Exception e) {
 // ...
}
                
viewPanel.getChildren().add(compositeRoot);

[/code]

Now I I just need to figure out how to populate the <insertChildren> and <insertFacets> elements in the facelet.
[Message sent by forum member 'janderssn' (janderssn)]

http://forums.java.net/jive/thread.jspa?messageID=354210