Esempio n. 1
0
  protected void encodeRowExpansion(FacesContext context, DataTable table) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    Map<String, String> params = context.getExternalContext().getRequestParameterMap();
    int expandedRowIndex =
        Integer.parseInt(params.get(table.getClientId(context) + "_expandedRowIndex"));
    String rowIndexVar = table.getRowIndexVar();

    table.setRowIndex(expandedRowIndex);

    if (rowIndexVar != null) {
      context.getExternalContext().getRequestMap().put(rowIndexVar, expandedRowIndex);
    }

    writer.startElement("tr", null);
    writer.writeAttribute("style", "display:none", null);
    writer.writeAttribute(
        "class", DataTable.EXPANDED_ROW_CONTENT_CLASS + " ui-widget-content", null);

    writer.startElement("td", null);
    writer.writeAttribute("colspan", table.getColumnsCount(), null);

    table.getRowExpansion().encodeAll(context);

    writer.endElement("td");

    writer.endElement("tr");

    table.setRowIndex(-1);
  }
Esempio n. 2
0
  protected void encodeRadio(
      FacesContext context, DataTable table, boolean checked, boolean disabled) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String boxClass = HTML.RADIOBUTTON_BOX_CLASS;
    String iconClass = HTML.RADIOBUTTON_ICON_CLASS;
    boxClass = disabled ? boxClass + " ui-state-disabled" : boxClass;
    boxClass = checked ? boxClass + " ui-state-active" : boxClass;
    iconClass = checked ? iconClass + " " + HTML.RADIOBUTTON_CHECKED_ICON_CLASS : iconClass;

    writer.startElement("div", null);
    writer.writeAttribute("class", HTML.RADIOBUTTON_CLASS, null);

    writer.startElement("div", null);
    writer.writeAttribute("class", "ui-helper-hidden-accessible", null);
    writer.startElement("input", null);
    writer.writeAttribute("type", "radio", null);
    writer.writeAttribute("name", table.getClientId(context) + "_radio", null);
    writer.endElement("input");
    writer.endElement("div");

    writer.startElement("div", null);
    writer.writeAttribute("class", boxClass, null);

    writer.startElement("span", null);
    writer.writeAttribute("class", iconClass, null);
    writer.endElement("span");

    writer.endElement("div");
    writer.endElement("div");
  }
Esempio n. 3
0
  protected void encodeFrozenRows(FacesContext context, DataTable table) throws IOException {
    Collection<?> frozenRows = table.getFrozenRows();
    if (frozenRows == null || frozenRows.isEmpty()) {
      return;
    }

    ResponseWriter writer = context.getResponseWriter();
    String clientId = table.getClientId(context);
    String var = table.getVar();
    String rowIndexVar = table.getRowIndexVar();
    Map<String, Object> requestMap = context.getExternalContext().getRequestMap();

    writer.startElement("tbody", null);
    writer.writeAttribute("class", DataTable.DATA_CLASS, null);

    int index = 0;
    for (Iterator<? extends Object> it = frozenRows.iterator(); it.hasNext(); ) {
      requestMap.put(var, it.next());

      if (rowIndexVar != null) {
        requestMap.put(rowIndexVar, index);
      }

      encodeRow(context, table, clientId, index, rowIndexVar);
    }

    writer.endElement("tbody");
  }
Esempio n. 4
0
  /** Render column headers either in single row or nested if a columnGroup is defined */
  protected void encodeThead(FacesContext context, DataTable table) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    ColumnGroup group = table.getColumnGroup("header");

    writer.startElement("thead", null);
    writer.writeAttribute("id", table.getClientId(context) + "_head", null);

    if (group != null && group.isRendered()) {

      for (UIComponent child : group.getChildren()) {
        if (child.isRendered() && child instanceof Row) {
          Row headerRow = (Row) child;

          writer.startElement("tr", null);

          for (UIComponent headerRowChild : headerRow.getChildren()) {
            if (headerRowChild.isRendered() && headerRowChild instanceof Column) {
              encodeColumnHeader(context, table, (Column) headerRowChild);
            }
          }

          writer.endElement("tr");
        }
      }

    } else {
      writer.startElement("tr", null);
      writer.writeAttribute("role", "row", null);

      for (UIColumn column : table.getColumns()) {
        if (column instanceof Column) {
          encodeColumnHeader(context, table, column);
        } else if (column instanceof DynamicColumn) {
          DynamicColumn dynamicColumn = (DynamicColumn) column;
          dynamicColumn.applyModel();

          encodeColumnHeader(context, table, dynamicColumn);
        }
      }

      writer.endElement("tr");
    }

    encodeFrozenRows(context, table);

    writer.endElement("thead");
  }
Esempio n. 5
0
  protected void encodeScript(FacesContext context, DataTable table) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String clientId = table.getClientId(context);
    String selectionMode = table.resolveSelectionMode();

    WidgetBuilder wb = getWidgetBuilder(context);
    wb.widget("DataTable", table.resolveWidgetVar(), clientId, true);

    // Pagination
    if (table.isPaginator()) {
      encodePaginatorConfig(context, table, wb);
    }

    // Selection
    wb.attr("selectionMode", selectionMode, null);

    // Filtering
    if (table.isFilteringEnabled()) {
      wb.attr("filter", true)
          .attr("filterEvent", table.getFilterEvent(), null)
          .attr("filterDelay", table.getFilterDelay(), Integer.MAX_VALUE);
    }

    // Row expansion
    if (table.getRowExpansion() != null) {
      wb.attr("expansion", true);
    }

    // Scrolling
    if (table.isScrollable()) {
      wb.attr("scrollable", true)
          .attr("liveScroll", table.isLiveScroll())
          .attr("scrollStep", table.getScrollRows())
          .attr("scrollLimit", table.getRowCount())
          .attr("scrollWidth", table.getScrollWidth(), null)
          .attr("scrollHeight", table.getScrollHeight(), null);
    }

    // Resizable/Draggable Columns
    wb.attr("resizableColumns", table.isResizableColumns(), false)
        .attr("liveResize", table.isLiveResize(), false)
        .attr("draggableColumns", table.isDraggableColumns(), false);

    // Editing
    if (table.isEditable()) {
      wb.attr("editable", true)
          .attr("editMode", table.getEditMode())
          .attr("cellSeparator", table.getCellSeparator(), null);
    }

    // MultiColumn Sorting
    if (table.isMultiSort()) {
      wb.attr("multiSort", true);
    }

    // Behaviors
    encodeClientBehaviors(context, table, wb);

    startScript(writer, clientId);
    writer.write(wb.build());
    endScript(writer);
  }
Esempio n. 6
0
  public void encodeTbody(FacesContext context, DataTable table, boolean dataOnly)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String rowIndexVar = table.getRowIndexVar();
    String clientId = table.getClientId(context);
    String emptyMessage = table.getEmptyMessage();
    UIComponent emptyFacet = table.getFacet("emptyMessage");
    SubTable subTable = table.getSubTable();
    SummaryRow summaryRow = table.getSummaryRow();

    if (table.isSelectionEnabled()) {
      table.findSelectedRowKeys();
    }

    int rows = table.getRows();
    int first = table.getFirst();
    int rowCount = table.getRowCount();
    int rowCountToRender =
        rows == 0 ? (table.isLiveScroll() ? table.getScrollRows() : rowCount) : rows;
    boolean hasData = rowCount > 0;

    if (!dataOnly) {
      writer.startElement("tbody", null);
      writer.writeAttribute("id", clientId + "_data", null);
      writer.writeAttribute("class", DataTable.DATA_CLASS, null);
    }

    if (hasData) {
      for (int i = first; i < (first + rowCountToRender); i++) {
        if (subTable != null) {
          encodeSubTable(context, table, subTable, i, rowIndexVar);
        } else {

          table.setRowIndex(i);
          if (!table.isRowAvailable()) {
            break;
          }

          encodeRow(context, table, clientId, i, rowIndexVar);

          if (summaryRow != null && !isInSameGroup(context, table, i)) {
            table.setRowIndex(i); // restore
            encodeSummaryRow(context, table, summaryRow);
          }
        }
      }
    } else {
      // Empty message
      writer.startElement("tr", null);
      writer.writeAttribute("class", DataTable.EMPTY_MESSAGE_ROW_CLASS, null);

      writer.startElement("td", null);
      writer.writeAttribute("colspan", table.getColumnsCount(), null);

      if (emptyFacet != null) emptyFacet.encodeAll(context);
      else writer.write(emptyMessage);

      writer.endElement("td");

      writer.endElement("tr");
    }

    if (!dataOnly) {
      writer.endElement("tbody");
    }

    // Cleanup
    table.setRowIndex(-1);
    if (rowIndexVar != null) {
      context.getExternalContext().getRequestMap().remove(rowIndexVar);
    }
  }
Esempio n. 7
0
  protected void encodeMarkup(FacesContext context, DataTable table) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    String clientId = table.getClientId(context);
    boolean scrollable = table.isScrollable();
    boolean hasPaginator = table.isPaginator();
    String style = table.getStyle();
    String paginatorPosition = table.getPaginatorPosition();

    // style class
    String containerClass =
        scrollable
            ? DataTable.CONTAINER_CLASS + " " + DataTable.SCROLLABLE_CONTAINER_CLASS
            : DataTable.CONTAINER_CLASS;
    containerClass =
        table.getStyleClass() != null
            ? containerClass + " " + table.getStyleClass()
            : containerClass;
    if (table.isResizableColumns())
      containerClass = containerClass + " " + DataTable.RESIZABLE_CONTAINER_CLASS;
    if (ComponentUtils.isRTL(context, table))
      containerClass = containerClass + " " + DataTable.RTL_CLASS;

    // default sort
    if (!table.isDefaultSorted() && table.getSortBy() != null && !table.isLazy()) {
      SortFeature sortFeature = (SortFeature) table.getFeature(DataTableFeatureKey.SORT);

      if (table.isMultiSort()) sortFeature.multiSort(context, table);
      else sortFeature.singleSort(context, table);

      table.setDefaultSorted();
    }

    if (hasPaginator) {
      table.calculateFirst();
    }

    writer.startElement("div", table);
    writer.writeAttribute("id", clientId, "id");
    writer.writeAttribute("class", containerClass, "styleClass");
    if (style != null) {
      writer.writeAttribute("style", style, "style");
    }

    encodeFacet(context, table, table.getHeader(), DataTable.HEADER_CLASS);

    if (hasPaginator && !paginatorPosition.equalsIgnoreCase("bottom")) {
      encodePaginatorMarkup(context, table, "top");
    }

    if (scrollable) {
      encodeScrollableTable(context, table);
    } else {
      encodeRegularTable(context, table);
    }

    if (hasPaginator && !paginatorPosition.equalsIgnoreCase("top")) {
      encodePaginatorMarkup(context, table, "bottom");
    }

    encodeFacet(context, table, table.getFooter(), DataTable.FOOTER_CLASS);

    if (table.isSelectionEnabled()) {
      encodeStateHolder(
          context,
          table,
          table.getClientId(context) + "_selection",
          table.getSelectedRowKeysAsString());
    }

    if (table.isDraggableColumns()) {
      encodeStateHolder(context, table, table.getClientId(context) + "_columnOrder", null);
    }

    if (scrollable) {
      encodeStateHolder(
          context, table, table.getClientId(context) + "_scrollState", table.getScrollState());
    }

    writer.endElement("div");
  }