Esempio n. 1
0
  protected void renderHeader(FacesContext context, UIComponent table, ResponseWriter writer)
      throws IOException {

    TableMetaInfo info = getMetaInfo(table);
    UIComponent header = getFacet(table, "header");
    String headerClass = (String) table.getAttributes().get("headerClass");
    if ((header != null) || (info.hasHeaderFacets)) {
      writer.startElement("thead", table);
      writer.writeText("\n", table, null);
    }
    if (header != null) {
      writer.startElement("tr", header);
      writer.startElement("th", header);
      if (headerClass != null) {
        writer.writeAttribute("class", headerClass, "headerClass");
      }
      writer.writeAttribute("colspan", String.valueOf(info.columns.size()), null);
      writer.writeAttribute("scope", "colgroup", null);
      encodeRecursive(context, header);
      writer.endElement("th");
      renderRowEnd(table, writer);
    }
    if (info.hasHeaderFacets) {
      writer.startElement("tr", table);
      writer.writeText("\n", table, null);
      for (UIColumn column : info.columns) {
        String columnHeaderClass = (String) column.getAttributes().get("headerClass");
        writer.startElement("th", column);
        if (columnHeaderClass != null) {
          writer.writeAttribute("class", columnHeaderClass, "columnHeaderClass");
        } else if (headerClass != null) {
          writer.writeAttribute("class", headerClass, "headerClass");
        }
        writer.writeAttribute("scope", "col", null);
        UIComponent facet = getFacet(column, "header");
        if (facet != null) {
          encodeRecursive(context, facet);
        }
        writer.endElement("th");
        writer.writeText("\n", table, null);
      }
      renderRowEnd(table, writer);
    }
    if ((header != null) || info.hasHeaderFacets) {
      writer.endElement("thead");
      writer.writeText("\n", table, null);
    }
  }
Esempio n. 2
0
  protected void renderRow(
      FacesContext context, UIComponent table, UIComponent child, ResponseWriter writer)
      throws IOException {

    // Iterate over the child UIColumn components for each row
    int columnStyleIdx = 0;
    TableMetaInfo info = getMetaInfo(table);
    for (UIColumn column : info.columns) {

      // Render the beginning of this cell
      boolean isRowHeader = Boolean.TRUE.equals(column.getAttributes().get("rowHeader"));
      if (isRowHeader) {
        writer.startElement("th", column);
        writer.writeAttribute("scope", "row", null);
      } else {
        writer.startElement("td", column);
      }

      if (info.columnClasses.length > 0) {
        writer.writeAttribute("class", info.columnClasses[columnStyleIdx++], "columnClasses");
        if (columnStyleIdx >= info.columnClasses.length) {
          columnStyleIdx = 0;
        }
      }

      // Render the contents of this cell by iterating over
      // the kids of our kids
      for (Iterator<UIComponent> gkids = getChildren(column); gkids.hasNext(); ) {
        encodeRecursive(context, gkids.next());
      }

      // Render the ending of this cell
      if (isRowHeader) {
        writer.endElement("th");
      } else {
        writer.endElement("td");
      }
      writer.writeText("\n", table, null);
    }
  }
Esempio n. 3
0
  public static void encodeOneRow(
      FacesContext facesContext,
      UIComponent component,
      SelectManyRendererBase renderer,
      ClientSelectItem clientSelectItem,
      String cssPrefix)
      throws IOException {
    AbstractSelectManyComponent table = (AbstractSelectManyComponent) component;
    String defaultItemCss = cssPrefix + ITEM_CSS;
    String defaultItemCssDis = cssPrefix + ITEM_CSS_DIS;

    ResponseWriter writer = facesContext.getResponseWriter();
    String clientId = table.getClientId(facesContext);
    String itemClientId = clientId + "Item" + clientSelectItem.getSortOrder();
    clientSelectItem.setClientId(itemClientId);
    writer.startElement(HtmlConstants.TR_ELEMENT, table);
    writer.writeAttribute("id", itemClientId, null);
    String itemCss;
    if (!table.isDisabled()) {
      itemCss = HtmlUtil.concatClasses(table.getItemClass(), defaultItemCss);
    } else {
      itemCss = HtmlUtil.concatClasses(table.getItemClass(), defaultItemCss, defaultItemCssDis);
    }
    writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, itemCss, null);

    String cellClassName = cssPrefix + CELL_CSS;

    String[] columnClasses;
    if (table.getColumnClasses() != null) {
      columnClasses = table.getColumnClasses().split(",");
    } else {
      columnClasses = new String[0];
    }
    int columnCounter = 0;
    Iterator<UIColumn> columnIterator = table.columns();
    while (columnIterator.hasNext()) {
      UIColumn column = columnIterator.next();
      if (column.isRendered()) {
        writer.startElement(HtmlConstants.TD_ELEM, table);

        Object width = column.getAttributes().get("width");
        if (width != null) {
          writer.writeAttribute(
              "style", "width: " + HtmlDimensions.formatSize(width.toString()), null);
        }

        String columnClass;
        if (columnClasses.length > 0) {
          columnClass =
              HtmlUtil.concatClasses(
                  cellClassName,
                  columnClasses[columnCounter % columnClasses.length],
                  column.getAttributes().get("styleClass"));
        } else {
          columnClass =
              HtmlUtil.concatClasses(cellClassName, column.getAttributes().get("styleClass"));
        }
        writer.writeAttribute("class", columnClass, null);
        renderer.renderChildren(facesContext, column);
        writer.endElement(HtmlConstants.TD_ELEM);
        columnCounter++;
      }
    }
    writer.endElement(HtmlConstants.TR_ELEMENT);
  }