Пример #1
0
 public XmlData toXmlData() {
   XmlData xd = new XmlData();
   for (DataColumn dc : belongToDT.getColumns()) {
     String n = dc.getName();
     Object o = this.getValue(n);
     if (o != null) xd.setParamValue(n, o);
   }
   return xd;
 }
Пример #2
0
  public void encodeColGroup(FacesContext context, DataTable table) throws IOException {
    ResponseWriter writer = context.getResponseWriter();

    writer.startElement("colgroup", null);
    for (UIColumn column : table.getColumns()) {
      if (column.isRendered()) {
        writer.startElement("col", null);
        writer.endElement("col");
      }
    }
    writer.endElement("colgroup");
  }
Пример #3
0
  public void fromXmlData(XmlData xd) {
    for (DataColumn dc : belongToDT.getColumns()) {
      String n = dc.getName();
      Object ov = xd.getParamValue(n);
      if (ov != null) { // 适应jdbc数据库访问要求
        if ((ov instanceof java.util.Date) && !(ov instanceof java.sql.Timestamp)) {
          ov = new java.sql.Timestamp(((java.util.Date) ov).getTime());
        }

        this.put(n, ov);
      }
    }
  }
Пример #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");
  }
Пример #5
0
  protected void encodeTFoot(FacesContext context, DataTable table) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    ColumnGroup group = table.getColumnGroup("footer");

    writer.startElement("tfoot", null);

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

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

          writer.startElement("tr", null);

          for (UIComponent footerRowChild : footerRow.getChildren()) {
            if (footerRowChild.isRendered() && footerRowChild instanceof Column) {
              encodeColumnFooter(context, table, (Column) footerRowChild);
            }
          }

          writer.endElement("tr");
        }
      }

    } else if (table.hasFooterColumn()) {
      writer.startElement("tr", null);

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

          encodeColumnFooter(context, table, dynamicColumn);
        }
      }

      writer.endElement("tr");
    }

    writer.endElement("tfoot");
  }
Пример #6
0
  public boolean encodeRow(
      FacesContext context, DataTable table, String clientId, int rowIndex, String rowIndexVar)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();

    boolean selectionEnabled = table.isSelectionEnabled();

    Object rowKey = null;
    if (selectionEnabled) {
      // try rowKey attribute
      rowKey = table.getRowKey();

      // ask selectable datamodel
      if (rowKey == null) rowKey = table.getRowKeyFromModel(table.getRowData());
    }

    // Preselection
    boolean selected = table.getSelectedRowKeys().contains(rowKey);

    String userRowStyleClass = table.getRowStyleClass();
    String rowStyleClass =
        rowIndex % 2 == 0
            ? DataTable.ROW_CLASS + " " + DataTable.EVEN_ROW_CLASS
            : DataTable.ROW_CLASS + " " + DataTable.ODD_ROW_CLASS;

    if (selected) {
      rowStyleClass = rowStyleClass + " ui-state-highlight";
    }

    if (userRowStyleClass != null) {
      rowStyleClass = rowStyleClass + " " + userRowStyleClass;
    }

    if (table.isEditingRow()) {
      rowStyleClass = rowStyleClass + " " + DataTable.EDITING_ROW_CLASS;
    }

    writer.startElement("tr", null);
    writer.writeAttribute("data-ri", rowIndex, null);
    if (rowKey != null) {
      writer.writeAttribute("data-rk", rowKey, null);
    }
    writer.writeAttribute("class", rowStyleClass, null);
    writer.writeAttribute("role", "row", null);
    if (selectionEnabled) {
      writer.writeAttribute("aria-selected", String.valueOf(selected), null);
    }

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

        encodeCell(context, table, dynamicColumn, null, false);
      }
    }

    writer.endElement("tr");

    return true;
  }