ravindersinghblujay / tableexport-for-vaadin

Automatically exported from code.google.com/p/tableexport-for-vaadin
0 stars 2 forks source link

Export from Grid over internal Table #41

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I created a internal Table from the Grid ContainerDataSource
2. For the ExcelExport i use the new Table, which is never displays on the ui 
(this is the point) as argument.
3. An Exception is raised in the TableExport.java when it tries to get the 
Application

What is the expected output? What do you see instead?
No exception when the Table is not on the gui

What version of the product are you using? On what operating system?
addon Version 1.5.1.5
Websphere 8.5 on AIX

Please provide any additional information below.
Call:

  Button bExport = new Button("Export");
            final String finalSelectedTable = selectedTable;
            bExport.addClickListener(new Button.ClickListener() {
                private static final long serialVersionUID = -73954695086117200L;
                private ExcelExport excelExport;

                @Override
                public void buttonClick(Button.ClickEvent clickEvent) {

                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
                    Date currDate = new Date();

                    Table table = new Table();
                    table.setContainerDataSource(grid.getContainerDataSource());
                    excelExport = new ExcelExport(table);
                    excelExport.excludeCollapsedColumns();
                    excelExport.setDisplayTotals(false);
                    excelExport.setRowHeaders(true);
                    excelExport.setDoubleDataFormat("0.00");
                    excelExport.setReportTitle(finalSelectedTable + " Report (" + sdf.format(currDate) + ")");
                    excelExport.setExportFileName(finalSelectedTable+"_"+sdf.format(currDate)+".xls");
                    excelExport.export();
                }
            });

            cl.addComponent(bExport,"export");

Changed code in TableExport.java
Old:

   protected boolean sendConvertedFileToUser(UI app, final File fileToExport,
            final String exportFileName) {
        TemporaryFileDownloadResource resource;
        try {
            resource =
                    new TemporaryFileDownloadResource(app, exportFileName, mimeType, fileToExport);
            app.getPage().open(resource, null, false);
        } catch (final FileNotFoundException e) {
            LOGGER.warning("Sending file to user failed with FileNotFoundException " + e);
            return false;
        }
        return true;
    }

New:

  protected boolean sendConvertedFileToUser(UI app, final File fileToExport,
            final String exportFileName) {
        TemporaryFileDownloadResource resource;

        if (app == null){
            app = UI.getCurrent();
        }

        try {
            resource =
                    new TemporaryFileDownloadResource(app, exportFileName, mimeType, fileToExport);
            app.getPage().open(resource, null, false);
        } catch (final FileNotFoundException e) {
            LOGGER.warning("Sending file to user failed with FileNotFoundException " + e);
            return false;
        }
        return true;
    }

Original issue reported on code.google.com by grames.g...@gmail.com on 31 Mar 2015 at 10:04