Search in sources :

Example 1 with ComponentUtil

use of com.sun.jsftemplating.component.ComponentUtil in project Payara by payara.

the class ListTreeAdaptor method getFacets.

/**
 *	<p> This method returns any facets that should be applied to the
 *	    <code>TreeNode (comp)</code>.  Useful facets for the sun
 *	    <code>TreeNode</code> component are: "content" and "image".</p>
 *
 *	<p> Facets that already exist on <code>comp</code>, or facets that
 *	    are directly added to <code>comp</code> do not need to be returned
 *	    from this method.</p>
 *
 *	<p> This implementation directly adds a "content" and "image" facet and
 *	    returns <code>null</code> from this method.</p>
 *
 *	@param	comp	    The tree node <code>UIComponent</code>.
 *	@param	nodeObject  The (model) object representing the tree node.
 */
public Map<String, UIComponent> getFacets(UIComponent comp, Object nodeObject) {
    if (nodeObject == null) {
        return null;
    }
    if ((nodeObject instanceof Integer) && nodeObject.equals(TOP_ID)) {
        // Top-level facets can be added directly, not needed here
        return null;
    }
    Properties props = new Properties();
    LayoutComponent desc = this.getLayoutComponent();
    // Check to see if a childActionListener was added
    // NOTE: This is not needed when a "command" event is used.  In the
    // case of a CommandEvent an ActionListener will be
    // automatically registered by the ComponentFactoryBase class
    // during "setOptions()".  Also, setting a childActionListener
    // here should not stop "command" handlers from being invoked.
    setProperty(props, "actionListener", desc.getOption("childActionListener"));
    // Also se the target and text...
    setProperty(props, "target", desc.getOption("childTarget"));
    // FIXME: Add support for other hyperlink properties??
    // Create Hyperlink
    // NOTE: Last attribute "content" will be the facet named used.
    FacesContext ctx = FacesContext.getCurrentInstance();
    ComponentUtil compUtil = ComponentUtil.getInstance(ctx);
    UIComponent imageLink = compUtil.getChild(comp, "imagelink", "com.sun.jsftemplating.component.factory.sun.ImageHyperlinkFactory", props, "image");
    // Force HTML renderer so we can use dynafaces safely.
    imageLink.setRendererType("com.sun.webui.jsf.ImageHyperlink");
    // We don't want the imageHyperlink to have the following property, so
    // set it after creating it
    setProperty(props, "text", comp.getAttributes().get("text"));
    UIComponent link = compUtil.getChild(comp, "link", "com.sun.jsftemplating.component.factory.sun.HyperlinkFactory", props, "content");
    // Force HTML renderer so we can use dynafaces safely.
    link.setRendererType("com.sun.webui.jsf.Hyperlink");
    // Check to see if we have a childURL, evalute it here (after component
    // is created, before rendered) so we can use the link itself to define
    // the URL.  This has proven to be useful...
    Object val = desc.getOption("childURL");
    if (val != null) {
        val = desc.resolveValue(ctx, link, val);
        link.getAttributes().put("url", val);
        imageLink.getAttributes().put("url", val);
    }
    // Set the image URL
    val = desc.getOption("childImageURL");
    if (val != null) {
        imageLink.getAttributes().put("imageURL", desc.resolveValue(ctx, link, val));
    }
    // Set href's handlers...
    // We do it this way rather than earlier b/c the factory will not
    // recognize this as a property, it requires it to be defined in the
    // LayoutComponent as a handler.  So we must do this manually like
    // this.
    List handlers = desc.getHandlers("childCommand");
    if (handlers != null) {
        link.getAttributes().put("command", handlers);
        imageLink.getAttributes().put("command", handlers);
        // This adds the required action listener to proces the commands
        // This is needed here b/c the factory has already executed -- the
        // factory is normally the place where this is added (iff there is
        // at least one command handler).
        (ActionSource.class.cast(link)).addActionListener(CommandActionListener.getInstance());
        (ActionSource.class.cast(imageLink)).addActionListener(CommandActionListener.getInstance());
    }
    // We already added the facet, return null...
    return null;
}
Also used : FacesContext(javax.faces.context.FacesContext) UIComponent(javax.faces.component.UIComponent) ComponentUtil(com.sun.jsftemplating.component.ComponentUtil) ArrayList(java.util.ArrayList) List(java.util.List) Properties(java.util.Properties) LayoutComponent(com.sun.jsftemplating.layout.descriptors.LayoutComponent)

Aggregations

ComponentUtil (com.sun.jsftemplating.component.ComponentUtil)1 LayoutComponent (com.sun.jsftemplating.layout.descriptors.LayoutComponent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 UIComponent (javax.faces.component.UIComponent)1 FacesContext (javax.faces.context.FacesContext)1