PDA

View Full Version : CSV Jasper Report download window


springnewbie
Sep 12th, 2007, 09:37 PM
I have to download a jasper report in CSV format and I have done the following configuration as mentioned below. The issue is once is click on save/cancel button of download window the popup window behind does not closes.

On the server side I set content-disposition header as attachment; filename=report.csv.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean id="jsReportViewResolver" class="org.springframework.web.servlet.view.BeanNameViewR esolver">
<property name="order"><value type="java.lang.Integer">0</value></property>
</bean>


<bean id="jasperReportsHtmlView" class="com.company.cc.reports.view.SortableJasperReportsH tmlView">
<property name="exporterClassName"><value>net.sf.jasperreports.engine.export.JRHtmlExporter</value></property>
<property name="useWriter"><value type="boolean">true</value></property>
<property name="contentType"><value>text/html</value></property>
<property name="outputType"><value>html</value></property>
</bean>

<bean id="jasperReportsPdfView" class="com.company.cc.reports.view.JasperReportsSingleFor matView">
<property name="exporterClassName"><value>net.sf.jasperreports.engine.export.JRPdfExporter</value></property>
<property name="useWriter"><value type="boolean">false</value></property>
<property name="contentType"><value>application/pdf</value></property>
<property name="outputType"><value>pdf</value></property>
</bean>

<bean id="jasperReportsCsvView" class="com.company.cc.reports.view.JasperReportsSingleFor matView">
<property name="exporterClassName"><value>com.company.cc.reports.export.CustomCsvExporter</value></property>
<property name="useWriter"><value type="boolean">true</value></property>
<property name="contentType"><value>text/csv</value></property>
<property name="outputType"><value>csv</value></property>
</bean>

<bean id="jasperReportsXlsView" class="com.company.cc.reports.view.JasperReportsSingleFor matView">
<property name="exporterClassName"><value>com.company.cc.reports.CustomXlsExporter</value></property>
<property name="useWriter"><value type="boolean">false</value></property>
<property name="contentType"><value>application/vnd.ms-excel</value></property>
<property name="outputType"><value>xls</value></property>
</bean>

<bean id="baseReportView"
class="com.company.cc.reports.CustomJasperReportsMultiFor matView" abstract="true">
<property name="jdbcDataSource"><ref bean="dataSource"/></property>
<property name="reportDataKey"><value>someInfo</value></property>
<property name="url"><value>/WEB-INF/jasperreports/someReport.jasper</value></property>
<property name="formatMappings">
<map>
<entry key="html"><ref local="jasperReportsHtmlView"/></entry>
<entry key="pdf"><ref local="jasperReportsPdfView"/></entry>
<entry key="csv"><ref local="jasperReportsCsvView"/></entry>
<entry key="xls"><ref local="jasperReportsXlsView"/></entry>
</map>
</property>
<property name="exporterParameters">
<map>
<entry key="net.sf.jasperreports.engine.export.JRXlsExporterPa rameter.IS_WHITE_PAGE_BACKGROUND">
<value type="boolean">true</value>
</entry>
<entry key="net.sf.jasperreports.engine.export.JRXlsExporterPa rameter.IS_ONE_PAGE_PER_SHEET">
<value type="boolean">true</value>
</entry>
<entry key="net.sf.jasperreports.engine.export.JRHtmlExporterP arameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS">
<value type="boolean">true</value>
</entry>
<entry key="net.sf.jasperreports.engine.export.JRHtmlExporterP arameter.IS_USING_IMAGES_TO_ALIGN">
<value type="boolean">false</value>
</entry>
<entry key="net.sf.jasperreports.engine.export.JRHtmlExporterP arameter.HTML_HEADER">
<value>
<![CDATA[
<html>
<head>
<!-- HTTP 1.1 -->
<meta http-equiv="Cache-Control" content="no-store"/>
<!-- HTTP 1.0 -->
<meta http-equiv="Pragma" content="no-cache"/>
<!-- Prevents caching at the Proxy Server -->
<meta http-equiv="Expires" content="0"/>
<meta http-equiv="Content-Type" content="text/html" charset=utf-8"/>
]]>
</value>
</entry>
</map>
</property>
<property name="contentDispositionMappings">
<props>
<prop key="html">inline; filename=report.html</prop>
<prop key="csv">attachment; filename=report.csv</prop>
<prop key="pdf">inline; filename=report.pdf</prop>
<prop key="xls">inline; filename=report.xls</prop>
</props>
</property>
</bean>

<bean id="ReportView" parent="baseReportView">

<property name="subReportUrls">
<map>
<entry key="subreport1">
<value>/WEB-INF/jasperreports/Tank.jasper</value>
</entry>
</map>
</property>
</bean>

</beans>


please let me know if there is any solution for closing the background window. I am testing this on IE

Jörg Heinicke
Sep 13th, 2007, 12:52 AM
The issue is once is click on save/cancel button of download window the popup window behind does not closes.

I guess the solution is just to not open the popup window.

Joerg

springnewbie
Sep 13th, 2007, 07:21 AM
User selects the report format upfront and then submits the form. As you see in configuration we do have xls and pdf formats as well. The popup windows for those configuration closes properly this happens only for csv format.

As mentioned, can you tell me how can I avoid opening of that window under these conditions.

Thanks

Jörg Heinicke
Sep 13th, 2007, 02:59 PM
As you see in configuration we do have xls and pdf formats as well.

But XLS and PDF are opened in the browser window, aren't they? From what I get this seems to be a pure client-side issue of opening a window or not (using target="_blank" or however you do it). Make this logic extension-aware.

Joerg

springnewbie
Sep 13th, 2007, 03:08 PM
Code is same for all report format. When the report is in CSV format and we click on Open instead of save it opens in MS excel view.... not embeded.

If we have xls report format and clicked on open it embeds it inside the brower window.

Some how IE does not know what to do with csv file format. Also since the code is same for all other format it shld behave similar.

Jörg Heinicke
Sep 13th, 2007, 03:11 PM
Also since the code is same for all other format it shld behave similar.

No, this is highly client-specific. Excel seems to register itself for the XLS content type but not for CSV. It's indeed hard to get a consistent behavior for different content types and browsers.

Joerg

springnewbie
Sep 13th, 2007, 03:15 PM
Just confirmed in my machine csv and xls are configured to be opened with MS Excel