webtier@glassfish.java.net

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

From: Lincoln Baxter, III <lincolnbaxter_at_gmail.com>
Date: Sat, 04 Apr 2009 12:32:40 -0400

When you get this working, could you please post the solution? I'm
interested in doing this as well.
It would be nice if there were some provided classes for doing this
nicely... this is a BIG potential selling point and could be a BIG
distinguishing factor between JSF2 and the rest of Wicket, Struts, and
other frameworks.

--Thanks
Lincoln

On Fri, 2009-04-03 at 10:13 -0700, Ryan Lubke wrote:

> 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
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>