Index: component/src/com/icesoft/faces/component/dataexporter/DataExporter.java =================================================================== --- component/src/com/icesoft/faces/component/dataexporter/DataExporter.java (revision 19020) +++ component/src/com/icesoft/faces/component/dataexporter/DataExporter.java Thu Jul 30 16:57:04 EEST 2009 @@ -28,7 +28,17 @@ public static final String COMPONENT_FAMILY = "com.icesoft.faces.DataExporter"; public static final String COMPONENT_TYPE = "com.icesoft.faces.DataExporter"; public static final String DEFAULT_RENDERER_TYPE = "com.icesoft.faces.DataExporterRenderer"; + private static final OutputTypeHandler NoopOutputHandler = new OutputTypeHandler("no-data") { + public void writeHeaderCell(String text, int col) { + } - + + public void writeCell(Object output, int col, int row) { + } + + public void flushFile() { + } + }; + private boolean readyToExport = false; private String _for; @@ -42,7 +52,7 @@ public final static String EXCEL_TYPE = "excel"; public final static String CSV_TYPE = "csv"; - public DataExporter() { + public DataExporter() { } /* @@ -257,34 +267,28 @@ .getCurrentInstance().getExternalContext().getSession(false)) .getServletContext(); - try { - File exportDir = new File(context.getRealPath("/export")); - if (!exportDir.exists()) - exportDir.mkdirs(); - String pathWithoutExt = context.getRealPath("/export") + "/export_" - + new Date().getTime(); + File exportDir = new File(context.getRealPath("/export")); + if (!exportDir.exists()) + exportDir.mkdirs(); + String pathWithoutExt = context.getRealPath("/export") + "/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"); + 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 { + outputHandler = NoopOutputHandler; - } + } - if (outputHandler == null) { - return null; - } - renderToHandler(outputHandler, uiData, fc); - setMimeType(outputHandler.getMimeType()); + renderToHandler(outputHandler, uiData, fc); + setMimeType(outputHandler.getMimeType()); - } catch (Exception e) { - e.printStackTrace(); + return outputHandler.getFile(); - } + } - return outputHandler != null ? outputHandler.getFile() : null; - } - private String encodeParentAndChildrenAsString(FacesContext fc, UIComponent uic, String str) { Object value = uic.getAttributes().get("value");