FilterTable to Table

Is there a way to convert a FilteringTable to Table? (aside from creating a new Table and using set and getContainerDataSource())

I am using the add-ons FilteringTable and TableExport and am having errors when creating the table right before export.

		
final Container filterTableContainer = <filterForFilterTable()>;
		FilterTable filterTable = new FilterTable();
		filterTable.setContainerDataSource(filterTableContainer);
		filterTable.setFiltersVisible(true);
		   
				
		Panel 	panelTab = new Panel();
				panelTab.addComponent(filterTable);
				panelTab.addComponent(exportButton);
		
				
		mainWindow.addComponent(panelTab);
		
		exportButton.addListener(new ClickListener() {
			
			private static final long serialVersionUID = 1L;
			private ExcelExport excelExport;
			private Table table;
			
			public void buttonClick(final ClickEvent event) {
				table = new Table();
				table.setContainerDataSource(filterTableContainer);
				excelExport = new ExcelExport(table);
				excelExport.excludeCollapsedColumns();
				excelExport.setDisplayTotals(false);
				excelExport.export();
				
			}
		});

error i get


com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in com.example.vaadinfirst.VaadinfirstApplication$1 failed.
	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:532)
	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
	at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1219)
	at com.vaadin.ui.Button.fireClick(Button.java:547)
	at com.vaadin.ui.Button.changeVariables(Button.java:214)
...
Caused by: java.lang.NullPointerException
	at com.vaadin.terminal.StreamResource.<init>(StreamResource.java:87)
	at com.vaadin.addon.tableexport.TemporaryFileDownloadResource.<init>(TemporaryFileDownloadResource.java:43)
	at com.vaadin.addon.tableexport.TableExport.sendConvertedFileToUser(TableExport.java:104)
	at com.vaadin.addon.tableexport.ExcelExport.sendConverted(ExcelExport.java:294)
	at com.vaadin.addon.tableexport.TableExport.export(TableExport.java:81)

I’m trying to avoid using too many Tables as my container has too many rows.

I am new to vaadin, and appreciate all the help I could get.

Thanks,
Teri

You can’t really convert a FilterTable into a Table as the latter doesn’t extend the former. What you do, by creating a new table and moving the container, is the closest thing I also come up with to use the two add-ons together. It
might
be that you lose some filtering in that process, but it just have to be tested out to be sure. The filtering in stored in the container so I think you are safe.

What you do should work because you are now only working with only one add-on inside the clicklistener. What I looked at the code, my guess would be that it has some issues with writing content into the temp file that will be sent to the user. If you are familiar with debugging code, that would be your best bet to figure out what goes wrong. Put a break point in the beginning in ExcelExport.sendConverted(), and debug all the way to the exception. It might be that the error has happend earlier, if the workbook.write(fileOut) doesn’t write anything to the file.

You can always also make an own implementation of TableExport, that you would use instead of ExcelExport.

Thanks Jens. debugging starts…
(or as you said, will have to implement my own TableExport. hello poi…) :slight_smile:

Hello!

Is there any other solution to this problem, or did you solve it, Teri? Exporting to Excel and Filtering a table are both pretty common tasks and it would seem people are commonly using the two together.

I’m in the same situation Teri was in, where I want to use TableExport together with FilteringTable. I get the same error and, additionaly, when debugging I get:

IOException while loading persisted sessions: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.apache.poi.hssf.usermodel.HSSFCellStyle
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.apache.poi.hssf.usermodel.HSSFCellStyle

In case there is no good solution to this, how would I go about making “my own implementation” of TableExport?

The second exception is mostly harmless - it comes from your server (Tomcat?) serializing sessions over server restarts and some Apache POI classes that are kept in session not being compatible with that, and just leads to the sessions being re-initialized. I’m not sure if those POI classes really need to be kept in the session, though, as I haven’t looked into the internals of TableExport.

You can disable that functionality in Tomcat by uncommenting the “Manager” line in the default context.xml or the server.

Ah, like I thought then. Feels good to let that particular nuisance slip aside from my mind for now!
Thank you Henri!

However, I’m still stuck with using the two addons together.
I’ve tried converting FilterTable to Table using the container from FilterTable (by using setContainerDataSource(filterTableContainer)), but it doesn’t seem to work right off the bat.

Hi All,

Kindly share the solutation if any one of you already have it. I am also facing same problem how to convert FilterTable to Table.

Hello,

I know this is an old topic, but people (just like myself) might look for a solution to this problem.

The reason for Teri’s nullpointer exception was that the TableExport addon (while exporting) was trying to get the actual vaadin UI through its Table parameter, which was null because he just created that temp Table to store the FilterTable’s data. The solution is to add the temp Table to the UI before trying to export. (You can set the Table to not be visible.)

exportTable = new Table(null, filterTable);
addComponent(exportTable);
exportTable.setVisible(false);          

btnExcelExp = new Button(null, new ClickListener() {
          private static final long serialVersionUID = 1L;
          @Override
          public void buttonClick(ClickEvent event) {
                    
              ExcelExport excelExport = new ExcelExport(exportTable);
              excelExport.excludeCollapsedColumns();
              excelExport.setReportTitle("Demo Report");
              excelExport.export();

          }
});
addComponent(btnExcelExp);

FilterTable is actually supported by the TableExport addon!

https://vaadin.com/forum/#!/thread/579717/5213742

“…There are two classes you should use in TableExport, CustomTableHolder and CustomTableExportableColumnGenerator, if you have a CustomTable…”

we can export FilterTable in excel. below code working for me…

final Button excelExportButton = new Button(“Export to Excel”);
final CustomTableHolder holder = new CustomTableHolder(table);

    excelExportButton.addListener(new ClickListener() {
        private ExcelExport excelExport;

        public void buttonClick(final ClickEvent event) {
            excelExport = new ExcelExport(holder, "Test Name", "Test Name", "LabTest122.xls");
            excelExport.excludeCollapsedColumns();
            excelExport.setReportTitle("Test Name");
            excelExport.export();
        }
    });

Cheers…