コード例 #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");
    }
  }
コード例 #2
0
 public static void encodeRows(
     FacesContext facesContext,
     UIComponent component,
     SelectManyRendererBase renderer,
     Iterator<ClientSelectItem> clientSelectItems,
     String cssPrefix)
     throws IOException {
   AbstractSelectManyComponent select = (AbstractSelectManyComponent) component;
   if (clientSelectItems != null && clientSelectItems.hasNext()) {
     String clientId = component.getClientId(facesContext);
     Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
     Object oldVar = requestMap.get(select.getVar());
     while (clientSelectItems.hasNext()) {
       ClientSelectItem clientSelectItem = clientSelectItems.next();
       requestMap.put(select.getVar(), clientSelectItem.getSelectItem().getValue());
       encodeOneRow(facesContext, component, renderer, clientSelectItem, cssPrefix);
     }
     requestMap.put(select.getVar(), oldVar);
     oldVar = null;
   }
 }
コード例 #3
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');
     }
   }
 }
コード例 #4
0
 public static List<ClientSelectItem> getClientSelectItems(
     FacesContext facesContext,
     AbstractSelectManyComponent select,
     Iterator<SelectItem> selectItems) {
   List<ClientSelectItem> clientSelectItems = new ArrayList<ClientSelectItem>();
   Object object = select.getValue();
   List values;
   if (object == null) {
     values = new ArrayList();
   } else if (object instanceof List) {
     values = (List) object;
   } else if (object instanceof Object[]) {
     values = Arrays.asList((Object[]) object);
   } else {
     throw new IllegalArgumentException(
         "Value expression must evaluate to either a List or Object[]");
   }
   int count = values.size();
   // TODO: Deal with SelectItemGroups
   while (selectItems.hasNext()) {
     SelectItem selectItem = selectItems.next();
     boolean selected;
     int sortOrder;
     if (values.contains(
         selectItem
             .getValue())) { // TODO: this requires value#equals() to be overridden. Redo with
                             // comparators?
       selected = true;
       sortOrder = values.indexOf(selectItem.getValue());
     } else {
       selected = false;
       sortOrder = count;
     }
     ClientSelectItem clientSelectItem =
         SelectHelper.generateClientSelectItem(
             facesContext, select, selectItem, sortOrder, selected);
     clientSelectItems.add(clientSelectItem);
     if (!selected) {
       count++;
     }
   }
   Collections.sort(clientSelectItems, clientSelectItemComparator);
   return clientSelectItems;
 }
コード例 #5
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);
  }