public UIData getUIData() { String forStr = getFor(); UIData forComp = (UIData) CoreComponentUtils.findComponent(forStr, this); if (forComp == null) { throw new IllegalArgumentException( "could not find UIData referenced by attribute @for = '" + forStr + "'"); } else if (!(forComp instanceof UIData)) { throw new IllegalArgumentException( "uiComponent referenced by attribute @for = '" + forStr + "' must be of type " + UIData.class.getName() + ", not type " + forComp.getClass().getName()); } // compare with cached DataModel to check for updates if (_origDataModelHash != 0 && _origDataModelHash != forComp.getValue().hashCode()) { reset(); } if (!isIgnorePagination() && ((first != Integer.MIN_VALUE && first != forComp.getFirst()) || (rows != Integer.MIN_VALUE && rows != forComp.getRows()))) { reset(); } Object value = forComp.getValue(); if (null != value) { _origDataModelHash = forComp.getValue().hashCode(); } return forComp; }
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(); }
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); } }