JasperReport inline not downloadable in Chrome

Components, Ajax Framework, Utilities and More.
Post Reply
erickdeoliveiraleal
Posts: 48
Joined: 25 Mar 2013, 13:00

14 Nov 2017, 20:02

I set my report to open inline, in a new tab, but sometimes the user want to download after view, with Chrome it is not working it tries to download a file called something.faces and the download doesn't complete, in Firefox I can download it, including the right name and extension. My code is as follows:

Code: Select all

public void gerarRelatorio(Map parametros, String arquivoModeloJasper, String nomeDownload) throws Exception {
		FacesContext fc = FacesContext.getCurrentInstance();
		ServletContext sc = (ServletContext) fc.getExternalContext().getContext();
		String pathRelatorios = sc.getRealPath("/relatorios/") + File.separator;

		parametros.put("SUBREPORT_DIR", pathRelatorios);
		parametros.put("urlImagemInterno", new Fixo().getServletFotoInterno());
		parametros.put("PASTA_IMAGENS", pathRelatorios);
		parametros.put("matricula", new UtilSiapen().getUsuarioLogado().getMatricula());
		try (Connection con = ConnectionFactory.getConnection();) {
			try {
				
				if ( new UtilSiapen().getUsuarioLogado().getId()!=null){
				new UtilAuditoriaJDBC().auditarExportRel(parametros, arquivoModeloJasper, con);}
				
				JasperPrint jasperPrint = JasperFillManager.fillReport(pathRelatorios + arquivoModeloJasper + ".jasper",
						parametros, con);

				HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();

				response.addHeader("Content-disposition", "inline; filename=\"" + nomeDownload + ".pdf\"");
				response.setContentType("application/pdf");

				ServletOutputStream out = response.getOutputStream();
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				JasperExportManager.exportReportToPdfStream(jasperPrint, baos);
				response.setContentLength(baos.size());
				baos.writeTo(out);

				UIViewRoot uiViewRoot = fc.getViewRoot();
				String viewId = uiViewRoot.getViewId();
				ViewDeclarationLanguage vdl = fc.getApplication().getViewHandler().getViewDeclarationLanguage(fc,
						viewId);
				StateManagementStrategy sms = vdl.getStateManagementStrategy(fc, viewId);
				sms.saveView(fc);
				fc.renderResponse();
				fc.responseComplete();
				response.getOutputStream().flush();
				response.getOutputStream().close();
				con.close();
			} catch (JRException e) {
				e.printStackTrace();
			}
		}
	}

Post Reply
  • Information
  • Who is online

    Users browsing this forum: alex83231 and 40 guests