protected void encodeAll()

in trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PanelAccordionRenderer.java [159:433]


  protected void encodeAll(
    FacesContext     context,
    RenderingContext rc,
    UIComponent      component,
    FacesBean        bean
    ) throws IOException
  {
    FormData fData = rc.getFormData();
    String formName = "";

    if (fData != null)
    {
      formName = fData.getName();
      if (formName == null)
      {
        _LOG.warning("PANELACCORDION_MUST_INSIDE_FORM");
        return;
      }
      // Hidden field to store parameter targetItem is needed for non
      // Ajax browsers to pass the target item Id back to the server.
      boolean pprEnabled =
        PartialPageUtils.supportsPartialRendering(rc);
      if (!pprEnabled)
      {
        fData.addNeededValue(XhtmlConstants.TARGETITEM_PARAM);
      }
    }

    List<UIComponent> children = component.getChildren();
    int numChildren = children.size();
    UIComponent disclosedChild = null;
    UIXShowDetail renderableChild = null;

    for (int indxChild = 0; indxChild < numChildren ; indxChild++ )
    {
      UIComponent child =  children.get(indxChild);
      if (! (child instanceof UIXShowDetail) )
      {
        continue;
      }

      UIXShowDetail detailChild =  (UIXShowDetail) children.get(indxChild);

      if (detailChild.isRendered())
      {
        // Mark the first renderable child
        if (_isItemDisabled(detailChild))
        {
          continue;
        }
        if (renderableChild == null)
        {
          renderableChild = detailChild;
        }
        if (detailChild.isDisclosed())
        {
          disclosedChild = detailChild;
          // A diclosed child found. return.
          break;
        }
      }
    }

    // If we have a minimum of 1 disclosed child and none have been disclosed
    // yet, disclose the first rendered one:
    if ( (disclosedChild == null) && !getDiscloseNone(component, bean) &&
      (renderableChild != null) && !renderableChild.isDisclosedTransient())
    {
      renderableChild.setDisclosed(true);
    }

    ResponseWriter out = context.getResponseWriter();
    String compId = component.getClientId(context);

    out.startElement("div", component);

    renderId(context, component);
    renderAllAttributes(context, rc, component, bean);

    boolean discloseMany = getDiscloseMany(component, bean);
    boolean discloseNone = getDiscloseNone(component, bean);
    boolean disclosedFixed = false;
    if (discloseMany && !discloseNone) // must keep at least one item disclosed
    {
      // This is a special case where we must determine if we have to fix the
      // disclosure state of one of the items.
      int disclosedCount = 0;
      for (UIComponent child : (List<UIComponent>) component.getChildren())
      {
        if (!(child instanceof UIXShowDetail) ||
            !child.isRendered())
          continue;

        UIXShowDetail detailItem = (UIXShowDetail) child;
        if (detailItem.isDisclosed())
        {
          disclosedCount++;
          if (disclosedCount > 1)
          {
            break; // we have enough information at this point to stop counting
          }
        }
      }
      if (disclosedCount <= 1)
      {
        disclosedFixed = true;
      }
    }

    boolean childAlreadyRendered = false;
    for (UIComponent child : (List<UIComponent>) component.getChildren())
    {
      if (!(child instanceof UIXShowDetail) ||
          !child.isRendered())
        continue;

      UIXShowDetail detailItem = (UIXShowDetail) child;
      boolean disabled = _isItemDisabled(detailItem);
      String titleText = (String)
        detailItem.getAttributes().get(CoreShowDetailItem.TEXT_KEY.getName());
      boolean disclosed = detailItem.isDisclosed();

      if (childAlreadyRendered)
      {
        // The detail child should be disclosed only when all three criteria met
        // 1. is marked as disclosed
        // 2. is not disabled and
        // 3. if a child is not already disclosed. This occurs when more than
        //    one showDetail child has it's disclosed property set to true.
        disclosed = false;
      }

      // Header renderer section.
      out.startElement("div", detailItem);

      String detailItemId = detailItem.getClientId(context);
      String itemStyleClass;
      if (disabled)
        itemStyleClass = getHeaderDisabledStyleClass();
      else if (disclosed)
        itemStyleClass = getHeaderExpandedStyleClass();
      else
        itemStyleClass = getHeaderCollapsedStyleClass();

      renderStyleClass(context, rc, itemStyleClass);

      // Render the toolbar component, if any (we use float to keep
      // the toolbar on the right - or left, in RTL languages - so
      // it has to be rendered first)
      UIComponent toolbar = getFacet(detailItem,
                                     CoreShowDetailItem.TOOLBAR_FACET);
      if (toolbar != null)
      {
        out.startElement("div", detailItem);
        renderStyleClass(context, rc, SkinSelectors.AF_PANELACCORDION_TOOLBAR_STYLE_CLASS);
        encodeChild(context, toolbar);
        out.endElement("div");
      }

      boolean javaScriptSupport = supportsScripting(rc);

      if (javaScriptSupport)
      {
        out.startElement("a", null);
        out.writeAttribute("name", detailItemId, null);
      }
      else
      {
        // For Non-JavaScript browsers, render an input element(type=submit) to
        // submit the page. Encode the name attribute with the parameter name
        // and value thus it would enable the browsers to include the name of
        // this element in its payLoad if it submits the page.
        out.startElement("input", null);
        out.writeAttribute("type", "submit", null);
      }

      renderStyleClass(context, rc,
                       disabled
                         ? getLinkDisabledStyleClass()
                         : getLinkEnabledStyleClass());

      // If the child is disclosable and enabled...
      boolean disclosable =
        discloseNone || (! disclosed) || (discloseMany && !disclosedFixed);
      if ( disclosable && (! disabled) )
      {
        boolean isImmediate = detailItem.isImmediate();
        String event = disclosed ? "hide" : "show";

        if (javaScriptSupport)
        {
          String onClickHandler = _getFormSubmitScript(component,
                                                       rc,
                                                       event,
                                                       detailItemId,
                                                       formName,
                                                       compId,
                                                       isImmediate);
          out.writeAttribute("onclick", onClickHandler, null);
          out.writeAttribute("href", "#", null);
        }
        else
        {
          String nameAttri = XhtmlUtils.getEncodedParameter
                                          (XhtmlConstants.SOURCE_PARAM)
                             + XhtmlUtils.getEncodedParameter(compId)
                             + XhtmlUtils.getEncodedParameter
                                         (XhtmlConstants.EVENT_PARAM)
                             + XhtmlUtils.getEncodedParameter(event)
                             + XhtmlUtils.getEncodedParameter
                                         (XhtmlConstants.TARGETITEM_PARAM)
                             + detailItemId;

          out.writeAttribute("name", nameAttri, null);
        }
      }

      if (javaScriptSupport)
      {
        // =-=rbaranwa Per the UI Review, no icon to be rendered when
        // panel is disabled.
        if (! disabled)
        {
          ShowDetailRenderer.renderDisclosureIcon(context,
                                                   rc,
                                                   disclosed,
                                                   getDisclosedTipKey(),
                                                   getUndisclosedTipKey());
        }
        if (titleText != null)
        {
          out.writeText(titleText, null);
        }
        out.endElement("a");
      }
      else
      {
        // Since we cannot render any image element as a child of input element,
        // just render the icon symbol along with the text.
        String icon = disclosed ? XhtmlConstants.NON_JS_DETAIL_DISCLOSED_ICON :
                                  XhtmlConstants.NON_JS_DETAIL_UNDISCLOSED_ICON;
        if (titleText != null)
        {
          icon = icon + titleText;
        }

        out.writeAttribute("value", icon, null);

        if (disabled || !disclosable)
        {
          out.writeAttribute("disabled", Boolean.TRUE, "disabled");
        }

        out.endElement("input");
      }

      out.endElement("div"); // Ending div for an individual panel


      // The detail child should be disclosed only when all three criteria met
      // 1. is marked as disclosed
      // 2. is not disabled and
      // 3. if a child is not already disclosed. This occurs when more than
      //    one showDetail child has it's disclosed property set to true.
      if (disclosed && (! disabled) && (! childAlreadyRendered) )
      {
        _encodeDetailItem(context, rc, component, detailItem, out);
        if (!discloseMany)
        {
          childAlreadyRendered = true;
        }
      }
    }
    out.endElement("div");
  }