Search code examples
excelwindowzk

Closing Excel window with ZK and Jasper Report


From a controller, I'm opening a new window to call a Jasper report. The problem it that new window (or tab depending of your browser) is blank when I choose an Excel format. I would like to close this window once the jasper/Excel is opened. How should I proceed to get the blank window closed? Or display teh Excel report in this new window?

Please note that for any other document type (PDF, HTML, etc.), the report is displayed in the new window/tab, which is ok.

Here's part of my code:

reports.java (controler)

Executions.getCurrent().sendRedirect("/app/rapport/displayReport.zul", "_blank");

displayReport.zul

<zk>
<jasperreport id="report" hflex="1" height="100%" width="100%"/>
<zscript><![CDATA[

        import org.cic.common.container.SessContext;
        import org.cic.fwd.ServiceLocator;
        import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

        SessContext sessContext = ServiceLocator.getSessContext();   

        report.setSrc((String)sessContext.get("src"));
        report.setDatasource((JRBeanCollectionDataSource)sessContext.get("datasource"));
        report.setParameters((Map)sessContext.get("parameters"));
        report.setType((String)sessContext.get("type"));
]]></zscript>
</zk>

Solution

  • Currently, there is no browser that can display an Excel file directly because there is no corresponding plugin. If displaying Excel is not your priority. I have 2 suggestions:

    1. Let users download Excel without opening new window

    In your controller, just create a excel file and let users download Refer to http://www.zkoss.org/zkdemo/file_handling/file_download

    1. Close new window with JS

    Close window in your controller of displayReport.zul. public class ReportComposer extends SelectorComposer<Component> { .. @Override public void doFinally() throws Exception { super.doFinally(); Clients.evalJavaScript("window.close();"); } }