empire-db-jakarta-faces/src/main/java/org/apache/empire/jakarta/components/LinkTag.java [180:404]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                        getFacets().put(UIComponent.COMPOSITE_FACET_NAME, facetComponent);
                    }
                }    
            }
            if (linkComponent == null)
            {   try {
                    creatingComponents = true;
                    linkComponent = createOutcomeTargetLink(context);
                    this.getChildren().add(0, linkComponent);
                    helper.saveComponentId(linkComponent);
                    // encode image
                    String imagePath = helper.getTagAttributeString("image");
                    if (StringUtils.isNotEmpty(imagePath))
                    {   // Create image
                        HtmlGraphicImage img = encodeImage(context, linkComponent, imagePath);
                        linkComponent.getChildren().add(img);
                        helper.saveComponentId(linkComponent);
                    }    
                    // done
                } finally {
                    creatingComponents = false;
                }
            }
            // set params
            setLinkProperties(linkComponent);
            addOrSetParams(linkComponent);
            // encode link
            this.encodeLinkChildren = isEncodeLinkChildren(linkComponent.getChildCount()>0 ? null : linkComponent.getValue());
            if (this.encodeLinkChildren)
                linkComponent.encodeBegin(context);
            else
            {   // default rendering (no children)
                linkComponent.setRendered(true);
                encodeLinkComponent(context, linkComponent);
                linkComponent.setRendered(false); // Don't render twice!
            }
        }
    }
    
    @Override 
    public void encodeChildren(FacesContext context) throws IOException 
    {
        // render
        if (this.encodeLinkChildren)
            super.encodeChildren(context);
    }

    /**
     * required for MenuItemTag
     * @param context the faces context
     * @throws IOException from base
     */
    public void forceEncodeChildren(FacesContext context) throws IOException 
    {
        super.encodeChildren(context);
    }
    
    @Override 
    public void encodeEnd(FacesContext context) throws IOException 
    {
        if (this.encodeLinkChildren)
        {
            if (isLinkDisabled())
            {   // Disabled
                ResponseWriter writer = context.getResponseWriter();
                writer.endElement(StringUtils.coalesce(this.disabledTagName, SPAN_ELEM));
            }
            else
            {   // Enabled
                HtmlOutcomeTargetLink link = getLinkComponent();
                if (link!=null && link.isRendered())
                    link.encodeEnd(context);
            }
        }
        // done
        super.encodeEnd(context);
    }
    
    protected String getLinkStyleClass()
    {
        return StringUtils.toString(getAttributes().get(InputControl.CSS_STYLE_CLASS));
    }
    
    protected boolean isLinkDisabled()
    {
        Object v = getAttributes().get("disabled");
        if (v==null)
            return false;
        // return disabled attribute
        return ObjectUtils.getBoolean(v); 
    }
    
    protected Object getLinkValue(boolean hasColumn)
    {
        // Is a column provided?
        if (hasColumn)
        {
            helper.prepareData();
            InputControl control = helper.getInputControl();
            InputControl.ValueInfo vi = helper.getValueInfo(FacesContext.getCurrentInstance());
            // return formatted value
            Object value = vi.getValue(true);
            return control.formatValue(value, vi, false);
        }
        else
        {   // An ordinary link
            String text = helper.getTagAttributeString("text");
            if (text!=null)
                return helper.getTextResolver(FacesContext.getCurrentInstance()).resolveText(text);
            // Use value
            Object value = getValue();
            return value;
        }
    }

    protected void setLinkProperties(HtmlOutcomeTargetLink link)
    {
        boolean hasColumn = helper.hasColumn();
        Object value = getLinkValue(hasColumn);
        link.setValue(value);
        /*
        if (helper.hasComponentId())
            link.setId(getId()+"_a");
        */    
        // css Style
        String cssStyle = helper.getSimpleStyleClass(getLinkStyleClass());
        link.setStyleClass(cssStyle);
        // Set Attributes
        Map<String,Object> attr = getAttributes();
        // Set outcome
        Object page = attr.get("page");
        String outcome = StringUtils.toString(page);
        link.setOutcome(outcome);
        // Copy attributes
        if ((value=attr.get("style"))!=null)
            link.setStyle(StringUtils.toString(value));
        if ((value=attr.get("tabindex"))!=null)
            link.setTabindex(StringUtils.toString(value));
        if ((value=attr.get("onclick"))!=null)
            link.setOnclick(StringUtils.toString(value));
        // title
        String title = helper.getTagAttributeString("title");
        if (StringUtils.isNotEmpty(title))
            link.setTitle(helper.getDisplayText(title));
        // include view param
        link.setIncludeViewParams(false);
    }

    protected void addOrSetParams(HtmlOutcomeTargetLink link)
    {
        addOrSetParam(link, "id", StringUtils.toString(getAttributes().get("idparam")));
    }
    
    protected void addOrSetParam(HtmlOutcomeTargetLink link, String paramName, String paramValue)
    {
        // Check params
        if (StringUtils.isEmpty(paramValue))
            return; // nothing to do 
        if (paramName==null || paramName.length()==0)
            throw new InvalidArgumentException("paramName", paramName);
        // find attribute
        List<UIComponent> l = link.getChildren();
        for (UIComponent c : l)
        {
            if (!(c instanceof UIParameter))
                continue;
            UIParameter p = (UIParameter)c; 
            if (p.getName().equalsIgnoreCase(paramName))
            {   // param existis
                p.setValue(paramValue);
                return;
            }
        }
        // Not found, hence add
        UIParameter param = new UIParameter();
        param.setName(paramName);
        param.setValue(paramValue);
        link.getChildren().add(param);
        helper.resetComponentId(param);
    }

    protected String writeStartElement(ResponseWriter writer)
        throws IOException
    {
        Map<String, Object> map = getAttributes();
        String tagName  = StringUtils.coalesce(StringUtils.toString(map.get("tag")), "span");
        String cssClass = helper.getTagStyleClass(null, null);        
        Object style = map.get("style");
        Object title = helper.getTagAttributeValue("title");
        // Write tag
        writer.startElement(tagName, this);
        helper.writeAttribute(writer, "class", cssClass);
        helper.writeAttribute(writer, "style", style);
        helper.writeAttribute(writer, "title", helper.hasColumn() ? helper.getValueTooltip(title) : title);
        return tagName;
    }

    protected HtmlOutcomeTargetLink createOutcomeTargetLink(FacesContext context)
    {
        // OutcomeTargetLink link 
        HtmlOutcomeTargetLink link = InputControlManager.createComponent(context, HtmlOutcomeTargetLink.class);
        return link;
    }
    
    protected HtmlOutcomeTargetLink getLinkComponent()
    {
        return (getChildCount()>0 ? (HtmlOutcomeTargetLink)getChildren().get(0) : null);
    }
    
    protected boolean isEncodeLinkChildren(Object linkValue)
    {
        return ObjectUtils.isEmpty(linkValue);
    }
    
    protected void encodeLinkComponent(FacesContext context, HtmlOutcomeTargetLink linkComponent)
        throws IOException
    {
        linkComponent.encodeAll(context);
    }
    
    protected HtmlGraphicImage encodeImage(FacesContext context, HtmlOutcomeTargetLink parent, String imagePath)
    {
        HtmlGraphicImage img = InputControlManager.createComponent(context, HtmlGraphicImage.class);
        img.setValue(imagePath);
        return img;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java [180:404]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                        getFacets().put(UIComponent.COMPOSITE_FACET_NAME, facetComponent);
                    }
                }    
            }
            if (linkComponent == null)
            {   try {
                    creatingComponents = true;
                    linkComponent = createOutcomeTargetLink(context);
                    this.getChildren().add(0, linkComponent);
                    helper.saveComponentId(linkComponent);
                    // encode image
                    String imagePath = helper.getTagAttributeString("image");
                    if (StringUtils.isNotEmpty(imagePath))
                    {   // Create image
                        HtmlGraphicImage img = encodeImage(context, linkComponent, imagePath);
                        linkComponent.getChildren().add(img);
                        helper.saveComponentId(linkComponent);
                    }    
                    // done
                } finally {
                    creatingComponents = false;
                }
            }
            // set params
            setLinkProperties(linkComponent);
            addOrSetParams(linkComponent);
            // encode link
            this.encodeLinkChildren = isEncodeLinkChildren(linkComponent.getChildCount()>0 ? null : linkComponent.getValue());
            if (this.encodeLinkChildren)
                linkComponent.encodeBegin(context);
            else
            {   // default rendering (no children)
                linkComponent.setRendered(true);
                encodeLinkComponent(context, linkComponent);
                linkComponent.setRendered(false); // Don't render twice!
            }
        }
    }
    
    @Override 
    public void encodeChildren(FacesContext context) throws IOException 
    {
        // render
        if (this.encodeLinkChildren)
            super.encodeChildren(context);
    }

    /**
     * required for MenuItemTag
     * @param context the faces context
     * @throws IOException from base
     */
    public void forceEncodeChildren(FacesContext context) throws IOException 
    {
        super.encodeChildren(context);
    }
    
    @Override 
    public void encodeEnd(FacesContext context) throws IOException 
    {
        if (this.encodeLinkChildren)
        {
            if (isLinkDisabled())
            {   // Disabled
                ResponseWriter writer = context.getResponseWriter();
                writer.endElement(StringUtils.coalesce(this.disabledTagName, SPAN_ELEM));
            }
            else
            {   // Enabled
                HtmlOutcomeTargetLink link = getLinkComponent();
                if (link!=null && link.isRendered())
                    link.encodeEnd(context);
            }
        }
        // done
        super.encodeEnd(context);
    }
    
    protected String getLinkStyleClass()
    {
        return StringUtils.toString(getAttributes().get(InputControl.CSS_STYLE_CLASS));
    }
    
    protected boolean isLinkDisabled()
    {
        Object v = getAttributes().get("disabled");
        if (v==null)
            return false;
        // return disabled attribute
        return ObjectUtils.getBoolean(v); 
    }
    
    protected Object getLinkValue(boolean hasColumn)
    {
        // Is a column provided?
        if (hasColumn)
        {
            helper.prepareData();
            InputControl control = helper.getInputControl();
            InputControl.ValueInfo vi = helper.getValueInfo(FacesContext.getCurrentInstance());
            // return formatted value
            Object value = vi.getValue(true);
            return control.formatValue(value, vi, false);
        }
        else
        {   // An ordinary link
            String text = helper.getTagAttributeString("text");
            if (text!=null)
                return helper.getTextResolver(FacesContext.getCurrentInstance()).resolveText(text);
            // Use value
            Object value = getValue();
            return value;
        }
    }

    protected void setLinkProperties(HtmlOutcomeTargetLink link)
    {
        boolean hasColumn = helper.hasColumn();
        Object value = getLinkValue(hasColumn);
        link.setValue(value);
        /*
        if (helper.hasComponentId())
            link.setId(getId()+"_a");
        */    
        // css Style
        String cssStyle = helper.getSimpleStyleClass(getLinkStyleClass());
        link.setStyleClass(cssStyle);
        // Set Attributes
        Map<String,Object> attr = getAttributes();
        // Set outcome
        Object page = attr.get("page");
        String outcome = StringUtils.toString(page);
        link.setOutcome(outcome);
        // Copy attributes
        if ((value=attr.get("style"))!=null)
            link.setStyle(StringUtils.toString(value));
        if ((value=attr.get("tabindex"))!=null)
            link.setTabindex(StringUtils.toString(value));
        if ((value=attr.get("onclick"))!=null)
            link.setOnclick(StringUtils.toString(value));
        // title
        String title = helper.getTagAttributeString("title");
        if (StringUtils.isNotEmpty(title))
            link.setTitle(helper.getDisplayText(title));
        // include view param
        link.setIncludeViewParams(false);
    }

    protected void addOrSetParams(HtmlOutcomeTargetLink link)
    {
        addOrSetParam(link, "id", StringUtils.toString(getAttributes().get("idparam")));
    }
    
    protected void addOrSetParam(HtmlOutcomeTargetLink link, String paramName, String paramValue)
    {
        // Check params
        if (StringUtils.isEmpty(paramValue))
            return; // nothing to do 
        if (paramName==null || paramName.length()==0)
            throw new InvalidArgumentException("paramName", paramName);
        // find attribute
        List<UIComponent> l = link.getChildren();
        for (UIComponent c : l)
        {
            if (!(c instanceof UIParameter))
                continue;
            UIParameter p = (UIParameter)c; 
            if (p.getName().equalsIgnoreCase(paramName))
            {   // param existis
                p.setValue(paramValue);
                return;
            }
        }
        // Not found, hence add
        UIParameter param = new UIParameter();
        param.setName(paramName);
        param.setValue(paramValue);
        link.getChildren().add(param);
        helper.resetComponentId(param);
    }

    protected String writeStartElement(ResponseWriter writer)
        throws IOException
    {
        Map<String, Object> map = getAttributes();
        String tagName  = StringUtils.coalesce(StringUtils.toString(map.get("tag")), "span");
        String cssClass = helper.getTagStyleClass(null, null);        
        Object style = map.get("style");
        Object title = helper.getTagAttributeValue("title");
        // Write tag
        writer.startElement(tagName, this);
        helper.writeAttribute(writer, "class", cssClass);
        helper.writeAttribute(writer, "style", style);
        helper.writeAttribute(writer, "title", helper.hasColumn() ? helper.getValueTooltip(title) : title);
        return tagName;
    }

    protected HtmlOutcomeTargetLink createOutcomeTargetLink(FacesContext context)
    {
        // OutcomeTargetLink link 
        HtmlOutcomeTargetLink link = InputControlManager.createComponent(context, HtmlOutcomeTargetLink.class);
        return link;
    }
    
    protected HtmlOutcomeTargetLink getLinkComponent()
    {
        return (getChildCount()>0 ? (HtmlOutcomeTargetLink)getChildren().get(0) : null);
    }
    
    protected boolean isEncodeLinkChildren(Object linkValue)
    {
        return ObjectUtils.isEmpty(linkValue);
    }
    
    protected void encodeLinkComponent(FacesContext context, HtmlOutcomeTargetLink linkComponent)
        throws IOException
    {
        linkComponent.encodeAll(context);
    }
    
    protected HtmlGraphicImage encodeImage(FacesContext context, HtmlOutcomeTargetLink parent, String imagePath)
    {
        HtmlGraphicImage img = InputControlManager.createComponent(context, HtmlGraphicImage.class);
        img.setValue(imagePath);
        return img;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



