Friday, July 13, 2012

Programmatic Facelet:create Composite Component

There is no official API way to do this before JSF 2.2.
Suppose we have this composite component under webapproot/resources/test/component.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns=""
    <title>This content will not be displayed</title>
        <composite:attribute name="tiptext" required="false" />
        <h:panelGroup styleClass="propertylabelcell">
            <composite:renderFacet name="firstfacet" required="false"></composite:renderFacet>
        A extra line of text
        <h:outputText value="#{cc.attrs.tiptext}"></h:outputText>

We can create one INSTANCE of this component programtically like this

FaceletFactory faceletFactory = (FaceletFactory) FactoryFinder
Map<String, Object> attrs=new HashMap<String, Object>();
attrs.put("tiptext", "this is a test tip");
        UIComponent component = faceletFactory.createComponent(
                "" + library, name, attrs);

No comments:

Post a Comment