Esempio n. 1
0
  public static void encodeHeader(
      FacesContext facesContext,
      UIComponent component,
      SelectManyRendererBase renderer,
      String rowClass,
      String cellClass)
      throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();
    AbstractSelectManyComponent select = (AbstractSelectManyComponent) component;
    Iterator<UIColumn> headers = select.columns();

    if (headers.hasNext()) {
      writer.startElement("tr", component);
      StringBuilder headerClass = new StringBuilder(rowClass);
      if (select.getHeaderClass() != null && !select.getHeaderClass().isEmpty()) {
        if (headerClass.length() > 0) {
          headerClass.append(" ");
        }
        headerClass.append(select.getHeaderClass());
      }

      writer.writeAttribute("class", headerClass, null);
      while (headers.hasNext()) {
        UIColumn header = headers.next();
        writer.startElement("th", component);
        writer.writeAttribute("class", cellClass, null);
        UIComponent facet = header.getFacet("header");
        if (facet != null && facet.isRendered()) {
          facet.encodeBegin(facesContext);
          if (facet.getRendersChildren()) {
            facet.encodeChildren(facesContext);
          } else {
            renderer.renderChildren(facesContext, facet);
          }
          facet.encodeEnd(facesContext);
        }
        writer.endElement("th");
      }
      writer.endElement("tr");
    }
  }
Esempio n. 2
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);
  }