webtier@glassfish.java.net

Re: [webtier] Programmatic creation of composite components in JSF 2.0

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Fri, 03 Apr 2009 10:13:53 -0700

On 3/31/09 5:50 AM, webtier_at_javadesktop.org wrote:
> Hi all
>
> With the cool JSF 2.0 composite component feature coming along, I would like to know if it is possible to programmatically add composite components to the component tree ?
>
> I have tried doing this inside a standard component binding i.e.<h:form binding="bb.setComponent"/> with the backing bean containing the following method:
>
> public void setComponent(UIComponent component) {
> UIComponent compositeComponent = application.createComponent(context, resource);
> UIPanel facetComponent = application.createComponent(UIPanel.COMPONENT_TYPE);
> facetComponent.setRendererType("javax.faces.Group");
> compositeComponent.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, facetComponent);
>
> FaceletContext faceletContext = (FaceletContext)context.getFacesContext().getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
> FaceletFactory faceletFactory = (FaceletFactory)RequestStateManager.get(context.getFacesContext(), RequestStateManager.FACELET_FACTORY);
>
> VariableMapper originalVariableMapper = faceletContext.getVariableMapper();
>
> faceletContext.setVariableMapper(new VariableMapperWrapper(originalVariableMapper));
> try {
> Facelet facelet = faceletFactory.getFacelet(compositeComponentResource.getURL());
> facelet.apply(context.getFacesContext(), facetComponent);
> } finally {
> faceletContext.setVariableMapper(originalVariableMapper);
> }
>
> component.getChildren().add(compositeComponent);
> }
>
> However this fails when performing a postback as the facelet context and factory are not present.
>
> For our purposes it would be really great if someone can provide instructions on how to do this programmatically.
>
How recent of a build are you using to try this out?
> thanks in advance :-)
> [Message sent by forum member 'genlbm' (genlbm)]
>
> http://forums.java.net/jive/thread.jspa?messageID=339830
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>
>