private void _encodeChildren()

in trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PanelFormLayoutRenderer.java [175:368]


  private void _encodeChildren(
    FacesContext     context,
    RenderingContext rc,
    UIComponent      component,
    FacesBean        bean,
    int              maxColumns,
    int              rows
    ) throws IOException
  {
    // We cannot render a nested panelForm with any more than a single column
    // so we must monitor whether we are nested or not:
    int nestLevel = _getNestLevel(context, -1) + 1;

    Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
    requestMap.put(_PANEL_FORM_LAYOUT_NEST_LEVEL_KEY, nestLevel);

    // Iterate through the childPeers extracting and counting the number of
    // rendered children, also count the rendered children inside of rendered groups:
    List<UIComponent> formChildren = component.getChildren();

    GroupingState renderedGroupingStates = new GroupingState(formChildren.size());

    UIXComponent.processFlattenedChildren(context,
                                          _renderedItemExtractor,
                                          formChildren,
                                          renderedGroupingStates);

    List<GroupState> renderedGroupStates = renderedGroupingStates.groupStates;

    int totalFormItemCount = renderedGroupStates.size();

    UIComponent footerFacetComponent = getFacet(component, "footer");

    // Iterate through the footerPeers extracting the rendered children:
    int totalFooterItemCount = 0;
    List<GroupState> footerGroupStates = null;
    if (footerFacetComponent != null)
    {
      GroupingState footerGroupingStates = new GroupingState(footerFacetComponent.getChildCount());

      UIXComponent.processFlattenedChildren(context,
                                            _renderedItemExtractor,
                                            footerFacetComponent,
                                            footerGroupingStates);
      footerGroupStates = footerGroupingStates.groupStates;
      totalFooterItemCount = footerGroupStates.size();
    }

    // convert the groupStates list into an array of sizes for each non-breakable group
    int[] renderedGroupSizes = new int[totalFormItemCount];
    int renderedGroupsCount = _computeRenderedGroupSizes(renderedGroupStates, renderedGroupSizes);

    // Now that we have the list and counts of rendered form items (and group
    // arrangements), we must figure out how many actual columns and actual rows
    // we really need:
    int actualColumns = maxColumns;
    int actualRows = rows;
    Object labelAlignment;

    // In the case of narrow-screen PDAs, the label and field are rendered
    // vertically to reduce the overall page's width. Thus, labelAlignment
    // is always "top" for narrow-screen PDAs.
    if (supportsNarrowScreen(rc))
    {
      labelAlignment = "top";
    }
    else
    {
      labelAlignment = _getLabelAlignment(component, bean);
    }

    boolean forceSingleColumn = (nestLevel != 0);
    boolean startAlignedLabels = !forceSingleColumn;
    if ("start".equals(labelAlignment))
    {
      startAlignedLabels = true;
    }
    else if ("top".equals(labelAlignment))
    {
      startAlignedLabels = false;
    }
    if ( forceSingleColumn || (totalFormItemCount == 0) )
    {
      // Must use a single column and unlimited rows:
      actualColumns = 1;
      actualRows = Integer.MAX_VALUE;
    }
    else if (actualColumns == 1)
    {
      // Developer wanted to use a single column and unlimited rows:
      actualRows = Integer.MAX_VALUE;
    }
    else
    {
      // We must compute how many rows will fit in the given max number of columns
      // and also see if there are actually fewer columns needed:
      Dimension actualResults = PanelFormLayoutRenderer._computeActualColumnsAndRows(
        actualColumns,
        actualRows,
        totalFormItemCount,
        renderedGroupSizes,
        renderedGroupsCount);
      actualColumns = (int)actualResults.getWidth();
      actualRows = (int)actualResults.getHeight();
    }

    if (actualColumns < 1)
    {
      return;
    }

    // These widths can either be pixels, percentages, or undefined.
    // We must ensure that if using percentages or undefined that we correct them
    // to total up properly.
    String labelWidth = (String)_getLabelWidth(component, bean);
    String fieldWidth = (String)_getFieldWidth(component, bean);

    // Create the DOM for the form:
    ResponseWriter rw = context.getResponseWriter();
    rw.startElement("table", null); // the outer table
    OutputUtils.renderLayoutTableAttributes(context, rc, "0", null);

    FormWidths effectiveWidths =
      _getFormWidths(startAlignedLabels, labelWidth, fieldWidth, actualColumns);
    rw.writeAttribute("style", "width: " + effectiveWidths.getOverallWidth(), null);

    rw.startElement("tbody", null); // the outer tbody
    rw.startElement("tr", null); // the outer row

    // build up list column and group starts for rendering
    List<LayoutAction> renderedLayoutActions =
                         _computeLayoutActions(actualRows, renderedGroupSizes, renderedGroupStates);

    // Create the form columns:

    ColumnEncodingState columnEncodingState = new ColumnEncodingState(
      rc,
      startAlignedLabels,
      effectiveWidths.getMainLabelWidth(),
      effectiveWidths.getMainFieldWidth(),
      actualColumns,
      actualRows,
      1, // colSpan
      renderedLayoutActions);

    UIXComponent.encodeFlattenedChildren(context,
                                         _formColumnEncoder,
                                         formChildren,
                                         columnEncodingState);

    rw.endElement("tr"); // the outer row

    // Create the column-spanning footer row(s):
    if (totalFooterItemCount > 0)
    {
      rw.startElement("tr", null); // the outer row

      // convert the footer group states into the encoding information for the footer
      int[] footerGroupSizes = new int[totalFooterItemCount];
      _computeRenderedGroupSizes(footerGroupStates, footerGroupSizes);

      List<LayoutAction> footerLayoutActions =
                  _computeLayoutActions(totalFooterItemCount, footerGroupSizes, footerGroupStates);

      ColumnEncodingState footerEncodingState = new ColumnEncodingState(
        rc,
        startAlignedLabels,
        effectiveWidths.getFooterLabelWidth(),
        effectiveWidths.getFooterFieldWidth(),
        1, // column count
        totalFooterItemCount, // row count
        actualColumns, // this is actually colSpan
        footerLayoutActions);

      UIXComponent.encodeFlattenedChild(context, _formColumnEncoder, footerFacetComponent, footerEncodingState);

      rw.endElement("tr"); // the outer row
    }

    // Indicate that we are leaving this level of nesting:
    if (nestLevel == 0)
    {
      // delete the value altogether:
      requestMap.remove(_PANEL_FORM_LAYOUT_NEST_LEVEL_KEY);
    }
    else
    {
      // decrement the value:
      requestMap.put(_PANEL_FORM_LAYOUT_NEST_LEVEL_KEY, nestLevel - 1);
    }

    rw.endElement("tbody"); // the outer tbody
    rw.endElement("table"); // the outer table
  }