Problema JSF 1.2 Jasper Reports exportar html

2 respostas
AndreNascimento21

Gostaria de saber se alguém pode me ajudar, estou usando jsf 1.2 e jasper 4.1.3, o codigo Funcioanar perfeitamente, o problema é que está renderizando o html na mesma pagina tipo em cima do formulario.

2 Respostas

AndreNascimento21
public void relatorioVencimentosHtml() {
		FacesContext faces = FacesContext.getCurrentInstance();
		HttpServletResponse response = (HttpServletResponse) faces.getExternalContext().getResponse();
		HttpServletRequest request = (HttpServletRequest) faces.getExternalContext().getRequest();
		
		String logo = getDiretorioReal("/imagens/mr/logoADA.jpg"); 
		String jasper = getDiretorioReal("/jasper/vencimentos.jasper");  
		String titulo = "Relatório Vencimento";
		
		// Parametros do relatorios
		Map<String, Object> parametros = new HashMap<String, Object>();
		parametros.put("P_LOGO", logo);
		parametros.put("P_TITULO", titulo);
		
		try {
			PrintWriter printWriter = response.getWriter();  
			ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
			JasperPrint jasperPrint = JasperFillManager.fillReport(jasper, parametros, conexao);
			
			JRHtmlExporter jrHtmlExporter = new JRHtmlExporter();

            response.setContentType("text/html");  
            response.setCharacterEncoding("ISO-8859-1");
            request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); 
            
            jrHtmlExporter.setParameter(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
            jrHtmlExporter.setParameter(JRExporterParameter.OUTPUT_WRITER, printWriter);  
            jrHtmlExporter.setParameter(JRExporterParameter.CHARACTER_ENCODING,"ISO-8859-1");  
                          
            //jrHtmlExporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, true);
            // To generate a HTML report we want configure ImageServlet in component.xml file of reporting UI bundle
            // Then want to set the  IMAGES_URI parameter
            jrHtmlExporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath() + "/image.servlet?image=");
            //  remove empty spaces
            jrHtmlExporter.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
            jrHtmlExporter.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.TRUE);
            jrHtmlExporter.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM, byteOutStream);
            jrHtmlExporter.exportReport();
            
		} catch (RuntimeException e) {
			throw e;
		} catch (Exception e) {
			System.err.println(e.getMessage());
			throw new FacesException(e);
		}
		finally{
			try {
				conexao.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
Reginaldo_Silva

Conseguiu resolver isto?

Criado 23 de novembro de 2011
Ultima resposta 26 de nov. de 2012
Respostas 2
Participantes 2