webtier@glassfish.java.net

Re: Programmatic or dynamic construction of composite components

From: <webtier_at_javadesktop.org>
Date: Sun, 28 Feb 2010 13:29:47 PST

So I thought that instead of emulating CompositeComponentTagHandler I could call CompositeComponentTagHandler and let it do its job. To do this I had to get (or create, whatever) the composite library and construct a ComponentConfig programmatically (which isn't a big problem). Here's what I came up with:

[pre]public void setComponent4(UIComponent component) {
                final CompositeComponentTagLibrary library = new CompositeComponentTagLibrary(
                                "http://java.sun.com/jsf/composite/components/dynamicfaces");
                try {
                        TagHandler tagHandler = library
                                        .createTagHandler(
                                                        "http://java.sun.com/jsf/composite/components/dynamicfaces",
                                                        "test",
                                                        new FakeComponentConfig(
                                                                        "http://java.sun.com/jsf/composite/components/dynamicfaces",
                                                                        "test", "d:test",
                                                                        UINamingContainer.COMPONENT_TYPE, null,
                                                                        new TagAttribute[] {
                                                                                        new TagAttributeImpl(new Location(
                                                                                                        "", -1, -1), "", "id",
                                                                                                        "id", "tag"),
                                                                                        new TagAttributeImpl(new Location(
                                                                                                        "", -1, -1), "", "value",
                                                                                                        "value",
                                                                                                        "#{stringValue.value}")

                                                                        }));
                        FaceletContext faceletContext = (FaceletContext) facesContext
                                        .getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);

                        tagHandler.apply(faceletContext, component);

                } catch (FaceletException fex) {
                        throw new FacesException(fex);
                } catch (IOException ioex) {
                        throw new FacesException(ioex);
                }
        }[/pre]

(I don't post the implementation of the FakeComponentConfig, it's quite straightforward).

So, this looks already much better since it does not mess with Facelets internals so much. Note that I had to construct an attribute for the value=#{stringValue.value} binding.

Nevertheless, the big problem with this code is that I can't add facets and children. It is OK to create a couple of attributes for known expressions (like value="#{stringValue.value}"), but it is simply not possible to construct a ComponentConfig for components which I'd like to add as children or facets.
[Message sent by forum member 'lexi' (valikov_at_gmx.net)]

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