protected void encodeAll()

in trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/GoButtonRenderer.java [71:250]


  protected void encodeAll(
    FacesContext     context,
    RenderingContext rc,
    UIComponent      component,
    FacesBean        bean
    ) throws IOException
  {
    String clientId = component.getClientId(context);
    if (canSkipRendering(rc, clientId))
      return;

    // Make sure we don't have anything to save
    assert(rc.getCurrentClientId() == null);
    rc.setCurrentClientId(clientId);

    String element;
    boolean useButton = false;
    boolean useInput = false;
    boolean supportScriptEvents = false;
    boolean imageLink = false;
    boolean iconAvailable = false;
    String icon = getIcon(component, bean);

    if (icon != null)
    {
      iconAvailable = true;
    }
    if ((supportsScripting(rc) && supportsIntrinsicEvents(rc)))
    {
      supportScriptEvents = true;
    }

    if (supportScriptEvents)
    {
      if (supportsAdvancedForms(rc))
      {
        element = XhtmlLafConstants.BUTTON_ELEMENT;
        useButton = true;
      }
      //if icon is set, render as an image element within a link element
      //since "buttons" html element is not supported and "input" element of
      //type=image does not support "onClick" JS handler.
      else if (iconAvailable && !supportsOnClickOnImgInput(rc))
      {
        element = XhtmlLafConstants.LINK_ELEMENT;
        imageLink = true;
      }
      else
      {
        element = XhtmlLafConstants.INPUT_ELEMENT;
        useInput = true;
      }
    }
    else
    {
      element = XhtmlLafConstants.LINK_ELEMENT;
    }

    ResponseWriter rw = context.getResponseWriter();
    boolean disabled = getDisabled(component, bean);
    rw.startElement(element, component);
    renderId(context, component);

    if (supportScriptEvents)
    {
      if (useInput && iconAvailable)
      {
        rw.writeAttribute("type", "image", null);
      }
      //For any element like <button> or <input> except <a> set type to "button"
      else if (!imageLink)
      {
        rw.writeAttribute("type", "button", null);
      }
      // If disabled, render "disable" only for <input> and <button> elements
      if (!imageLink && disabled)
      {
        rw.writeAttribute("disabled", Boolean.TRUE, "disabled");
      }
    }

    if (disabled || !supportsNavigation(rc))
    {
      // Skip over event attributes when disabled
      renderStyleAttributes(context, rc, component, bean);
    }
    else
    {
      renderAllAttributes(context, rc, component, bean);
      if (supportScriptEvents)
      {
        rw.writeAttribute("onclick", getButtonOnclick(component, bean), null);
        if (imageLink)
        {
          renderEncodedActionURI(context, XhtmlConstants.HREF_ATTRIBUTE, "#");
        }
      }
      else
      {
        renderEncodedActionURI(context, XhtmlConstants.HREF_ATTRIBUTE,
          getDestination(component, bean));

        if (supportsTarget(rc))
        {
          rw.writeAttribute("target", getTargetFrame(component, bean), null);
        }
      }
    }

    // Write the text and access key

    char accessKey;
    if (supportsAccessKeys(rc))
    {
      accessKey = getAccessKey(component, bean);
      if (accessKey != CHAR_UNDEFINED)
      {
        rw.writeAttribute("accesskey",
                          Character.valueOf(accessKey),
                          "accessKey");
      }
    }
    else
    {
      accessKey = CHAR_UNDEFINED;
    }

    String text = getText(component, bean);

    if (useButton)
    {

      AccessKeyUtils.renderAccessKeyText(context,
                                         text,
                                         accessKey,
                                         SkinSelectors.AF_ACCESSKEY_STYLE_CLASS);
      if (icon != null)
        OutputUtils.renderImage(context, rc, icon, null, null, null,
                                  getShortDesc(component, bean));
    }
    // For PDAs, render only the image if icon is available
    else if (!supportScriptEvents)
    {
      if(iconAvailable)
      {

       OutputUtils.renderImage(context, rc, icon, null, null, null,
                                  getShortDesc(component, bean));
      }
      else
      {

       AccessKeyUtils.renderAccessKeyText(context,
                                         text,
                                         accessKey,
                                         SkinSelectors.AF_ACCESSKEY_STYLE_CLASS);
      }
    }
    else
    {
      // Render an image tag inside the anchor tag
      if (imageLink)
      {
        OutputUtils.renderImage(context, rc, icon, null, null, null,
                                getShortDesc(component, bean));
      }
      // For input element render src attribute to the url of the icon
      else if (iconAvailable)
      {
        renderEncodedResourceURI(context, "src", icon);
      }
      else
      {
        rw.writeAttribute("value", text, "text");
      }
    }

    rw.endElement(element);
    rc.setCurrentClientId(null);
  }