Exemplo n.º 1
0
 public static void encodeItems(
     FacesContext facesContext,
     UIComponent component,
     Iterator<ClientSelectItem> clientSelectItems,
     String cssPrefix)
     throws IOException {
   AbstractSelectManyComponent select = (AbstractSelectManyComponent) component;
   String defaultItemCss = cssPrefix + ITEM_CSS;
   String defaultItemCssDis = cssPrefix + ITEM_CSS_DIS;
   if (clientSelectItems != null && clientSelectItems.hasNext()) {
     ResponseWriter writer = facesContext.getResponseWriter();
     String clientId = component.getClientId(facesContext);
     while (clientSelectItems.hasNext()) {
       ClientSelectItem clientSelectItem = clientSelectItems.next();
       String itemClientId = clientId + "Item" + clientSelectItem.getSortOrder();
       clientSelectItem.setClientId(itemClientId);
       writer.startElement(HtmlConstants.DIV_ELEM, component);
       writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, itemClientId, null);
       String itemCss;
       if (!select.isDisabled()) {
         itemCss = HtmlUtil.concatClasses(select.getItemClass(), defaultItemCss);
       } else {
         itemCss =
             HtmlUtil.concatClasses(select.getItemClass(), defaultItemCss, defaultItemCssDis);
       }
       writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, itemCss, null);
       String label = clientSelectItem.getLabel();
       if (label != null && label.trim().length() > 0) {
         writer.writeText(label, null);
       } else {
         writer.write("\u00a0");
       }
       writer.endElement(HtmlConstants.DIV_ELEM);
       writer.write('\n');
     }
   }
 }
Exemplo 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);
  }