View Single Post
  #1 (permalink)  
Old January 12th, 2012, 06:59 AM
jaykio77 jaykio77 is offline
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs down Send ArrayList from jsf to jasperreport as Datasource

Hello Forum.
i have an array list in jsf bean that i want user to print via jasperreport.
i followed following steps.
1. use empty datasource in jasper report.
2. created Fields in jasper reports as those of my bean properties.
i tried both (Employee.name) and only name.
3. then i compiled the report to employeeList.jasper and placed that in my
/reports/EmployeeReports/employeeList.jasper folder in jsf project.
4. I have then used following code to fill and show the pdf report to user
Code:
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(this.srchdEmployeesList);
		FacesContext facesContext = FacesContext.getCurrentInstance();
		HttpServletResponse response = (HttpServletResponse)facesContext.getExternalContext().getResponse();
		HashMap parameterMap = new HashMap();
		JasperPrint jasperPrint = JasperFillManager.fillReport("/reports/EmployeeReports/employeeList.jasper", parameterMap, dataSource);
		InputStream reportStream = facesContext.getExternalContext().getResourceAsStream("/reports/EmployeeReports/employeeList.jasper");
		ServletOutputStream servletOutputStream = response.getOutputStream();
		Class.forName("oracle.jdbc.driver.OracleDriver");
		Session hibernateSession = null;
		hibernateSession = HibernateUtils.currentSession();
		connection = hibernateSession.connection();
		facesContext.responseComplete();
		response.setContentType("application/pdf");
		response.setHeader("Content-disposition", "attachment;");
JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream, parameterMap, connection);
but the problem is, my report is not filling. Plz let me know where am i wrong. i will be obliged.

Last edited by jaykio77; January 14th, 2012 at 02:47 AM.. Reason: place tags for the code
Reply With Quote