Announcement Announcement Module
Collapse
No announcement yet.
Set Content-Disposition in Controller on a Jasper view Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Set Content-Disposition in Controller on a Jasper view

    How can I set Content-Disposition in my controller code? The view is a JasperReportsMultiFormatView

    Code:
    model.put("ReportName", "Report");
    model.put("dataSource", getData());
    model.put("format", "pdf");
            
    Properties headers = new Properties();
    headers.setProperty("Content-Disposition", "attachment; filename=my_report_name.pdf");
    model.put("headers", headers);
    I want to switch from attachment/inline based on the POST params and change de filename dynamically, getting it from the POST or some another resource...But I don't want to create views for each option in my views.properties

  • #2
    You'll need to override one of the methods (depending on which controller you are extending) that take the response as a parameter.

    Comment


    • #3
      The docs of AbstractJasperReportsView says:

      Response headers can be controlled via the headers property. Spring will attempt to set the correct value for the Content-Diposition header so that reports render correctly in Internet Explorer. However, you can override this setting through the headers property.
      It's not a Controller case. It's how can I instruct de View to read de headers property by code...

      Examining the sources of org.springframework.web.servlet.view.jasperreports package I cant understand if I need to extends JasperReportsMultiFormatView or not..

      Any help will be welcome

      Comment


      • #4
        Originally posted by caetano
        The docs of AbstractJasperReportsView says:

        Response headers can be controlled via the headers property. Spring will attempt to set the correct value for the Content-Diposition header so that reports render correctly in Internet Explorer. However, you can override this setting through the headers property.
        I think it's referring to the headers property on the view instance itself (injected from the definition), rather than the model object. I suspect you'll have to extend the class and override getHeaders() in order to prepare the headers properties dynamically.

        Comment


        • #5
          Code:
          	 <bean id="certificadoPdf" class="org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView">
          		<property name="reportCompiler"><ref local="jRBshCompiler"/></property>
          		<property name="headers">
                      <props>
                          <prop key="Content-Disposition">        
                               attachment; filename=certificado.pdf
                          </prop>
                      </props>
          		</property>
          		<property name="url">
          			<value>/WEB-INF/reports/certificado_frente.jrxml</value>
          		</property>
          		<property name="subReportUrls">
          			<map>
          				<entry key="certificadoVerso">
          					<value>/WEB-INF/reports/certificado_verso.jrxml</value>
          				</entry>
          			</map>
          		</property>
          		<property name="reportDataKey">
          			<value>dataSource</value>
          		</property>
          	</bean>
          Hope this help!
          Gilberto

          Comment

          Working...
          X