Пример #1
0
 protected void processColumnHeader(
     FacesContext fc, OutputTypeHandler outputHandler, UIComponent uiColumn, int colIndex) {
   UIComponent headerComp = uiColumn.getFacet("header");
   if (headerComp != null) {
     String headerText = encodeParentAndChildrenAsString(fc, headerComp);
     if (headerText != null) {
       outputHandler.writeHeaderCell(headerText, colIndex);
     }
   }
 }
Пример #2
0
  private void renderToHandler(OutputTypeHandler outputHandler, UIData uiData, FacesContext fc) {

    try {
      int rowIndex = 0;
      int numberOfRowsToDisplay = 0;
      if (!isIgnorePagination()) {
        rowIndex = uiData.getFirst();
        numberOfRowsToDisplay = uiData.getRows();
        first = rowIndex;
        rows = numberOfRowsToDisplay;
      }

      int countOfRowsDisplayed = 0;
      uiData.setRowIndex(rowIndex);
      String[] includeColumnsArray = null;
      String includeColumns = getIncludeColumns();
      if (includeColumns != null) includeColumnsArray = includeColumns.split(",");
      List columns = getRenderedChildColumnsList(uiData);
      // System.out.println("DataExporter.renderToHandler()  columns.size: " + columns.size());

      // write header
      // System.out.println("DataExporter.renderToHandler()  HEADERS");
      processAllColumns(fc, outputHandler, columns, includeColumnsArray, -1, false);

      // System.out.println("DataExporter.renderToHandler()  ROWS");
      while (uiData.isRowAvailable()) {
        if (numberOfRowsToDisplay > 0 && countOfRowsDisplayed >= numberOfRowsToDisplay) {
          break;
        }

        // render the child columns; each one in a td
        processAllColumns(
            fc, outputHandler, columns, includeColumnsArray, countOfRowsDisplayed, false);

        // keep track of rows displayed
        countOfRowsDisplayed++;
        // maintain the row index property on the underlying UIData
        // component
        rowIndex++;
        uiData.setRowIndex(rowIndex);
      }
      // reset the underlying UIData component
      uiData.setRowIndex(-1);

      // write footer
      // System.out.println("DataExporter.renderToHandler()  FOOTERS");
      processAllColumns(
          fc, outputHandler, columns, includeColumnsArray, countOfRowsDisplayed, true);

      outputHandler.flushFile();
    } catch (Exception e) {
      log.error("renderToHandler()", e);
    }
  }
Пример #3
0
  private File createFile(FacesContext fc, String type, UIData uiData) {
    OutputTypeHandler outputHandler = null;
    String path = CoreUtils.getRealPath(fc, "/export");
    File exportDir = new File(path);
    if (!exportDir.exists()) exportDir.mkdirs();
    String pathWithoutExt = path + "/export_" + new Date().getTime();

    if (getOutputTypeHandler() != null) outputHandler = getOutputTypeHandler();
    else if (DataExporter.EXCEL_TYPE.equals(getType())) {
      outputHandler = new ExcelOutputHandler(pathWithoutExt + ".xls", fc, uiData.getId());
    } else if (DataExporter.CSV_TYPE.equals(getType())) {
      outputHandler = new CSVOutputHandler(pathWithoutExt + ".csv");
    } else if (DataExporter.PDF_TYPE.equals(getType())) {
      outputHandler = new PDFOutputHandler(pathWithoutExt + ".pdf", uiData.getId());
    } else {
      outputHandler = NoopOutputHandler;
    }
    renderToHandler(outputHandler, uiData, fc);
    setMimeType(outputHandler.getMimeType());

    return outputHandler.getFile();
  }
Пример #4
0
 protected void processColumnFooter(
     FacesContext fc,
     OutputTypeHandler outputHandler,
     UIComponent uiColumn,
     int colIndex,
     int countOfRowsDisplayed) {
   UIComponent footerComp = uiColumn.getFacet("footer");
   if (footerComp != null) {
     Object output = encodeParentAndChildrenAsString(fc, footerComp);
     if (output != null) {
       outputHandler.writeFooterCell(output, colIndex, countOfRowsDisplayed);
     }
   }
 }
Пример #5
0
  protected void processColumn(
      FacesContext fc,
      OutputTypeHandler outputHandler,
      UIComponent uiColumn,
      int colIndex,
      int countOfRowsDisplayed) {
    StringBuffer stringOutput = new StringBuffer();

    Iterator childrenOfThisColumn = uiColumn.getChildren().iterator();
    while (childrenOfThisColumn.hasNext()) {

      UIComponent nextChild = (UIComponent) childrenOfThisColumn.next();
      if (nextChild.isRendered() && !(nextChild instanceof RowSelector)) {
        stringOutput.append(encodeParentAndChildrenAsString(fc, nextChild));
        // a blank to separate
        if (childrenOfThisColumn.hasNext()) {
          stringOutput.append(' ');
        }
      }
    }
    outputHandler.writeCell(stringOutput.toString(), colIndex, countOfRowsDisplayed);
  }