[jboss-user] [JBoss Seam] - Re: servlet functionality with seam component

swd847 do-not-reply at jboss.com
Wed Oct 3 02:24:32 EDT 2007


I was asking the same question not long ago. Here is an easy way to return a pdf from an action method (in this case a Jasper Report):


  | byte[] data = JasperRunManager.runReportToPdf(compileDir
  | 						+ report.getReport() + ".jasper", params);
  | 
  | 				FacesContext facesContext = FacesContext.getCurrentInstance();
  | 				HttpServletResponse response = (HttpServletResponse) facesContext
  | 						.getExternalContext().getResponse();
  | 				response.setContentType("application/pdf");
  | 				response.setContentLength(data.length);
  | 				response.setHeader("Content-disposition",
  | 						"attachment;filename=report.pdf");
  | 
  | 				try {
  | 
  | 					OutputStream out = response.getOutputStream();
  | 
  | 					out.write(data);
  | 
  | 					out.flush();
  | 					out.close();
  | 
  | 					facesContext.responseComplete();
  | 				} catch (IOException ex) {
  | 					FacesMessages.instance().add(
  | 							"Error while downloading the file: report.pdf");
  | 				}
  | 
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4090891#4090891

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4090891



More information about the jboss-user mailing list