Reporting and JSF Possibilities, solutions, challenges Slide 1
Agenda What is reporting? Why do we need it? The JSF example application Introduction to reporting engines Overview Eclipse BIRT JasperReports Integration into JSF Eclipse BIRT JasperReports Conclusion Slide 2
Who am I? Name: Andy Bosch Trainer, Coach, Developer, Specialized on JSF und Portlets Expert Group member of JSR-301 and JSR-329 Editor of www.jsf-forum.de and www.jsf-portlets.net Working with JSF since 2004 Slide 3
Agenda What is reporting? Why do we need it? The JSF example application Introduction to reporting engines Overview Eclipse BIRT JasperReports Integration into JSF Eclipse BIRT JasperReports Conclusion Slide 4
What is reporting? Monthly contracts January 31 February 28 March 34 April 22 May 17 June 29 Slide 5
From data to knowledge Costs Plain data Information Data and additional meaning Knowledge Information which can be analyzed Only characters and numbers Benefit Slide 6
Where to find the data? Slide 7
Once upon a time Boss: I need some figures about our last month sales. It s very urgent. Developer: Uh, I can write a sql script which collects all the data, but it will take about 2 hours Boss: But you did it last month, right? Developer: Yes, I will see if I can find the sql again in my waste bin Boss: And please don t forget to create a nice looking chart! Developer: Really?. I hate MS-Excel Is there any way you can do this on your own? Boss: No, I don t understand SQL. Please do take care of it. Slide 8
Reporting Engines done by yourself - Using itext or Xslt (Apache Fop) - Jakarta POI or JExcelAPI Pros - Easy to create simple solutions - Good for smaller requirements Cons - Only a programmer can change the report design - Everything is done in the Java source code - Limited only to Pdf or Excel as output format - Many many lines of code Slide 9
We need a real reporting solution - A reporting engines helps you to create reports. - A reporting engines helps you to visualize your reports. - You can see up-to-date reports again and again. - You have to invest time and knowledge only once to create good-looking and meaningful reports - When integrated in a web application, customers can view the reports within their familiar environment. Slide 10
BI, MIS, DSS Reporting is not cutting edge. Terms in ealier times: - MIS: Management Information Systems - DSS: Decision Support Systems - EIS: Executive Information Systems - BI: Business Intelligence Slide 11
The goal: Reports integrated in JSF apps - Web application - UI is based on JSF - User should be able to view reports inside the web application - Reports shouldn t be hard coded. - User should be able to add additional reports. Slide 12
Agenda What is reporting? Why do we need it? The JSF example application Introduction to reporting engines Overview Eclipse BIRT JasperReports Integration into JSF Eclipse BIRT JasperReports Conclusion Slide 13
Do you all know JSF? JavaServer Faces is a framework. It is not a ready-to-use product, just a framework which offers the possibility to build web applications. A framework usually includes best practices. JavaServer Faces is focused on the user interface. JavaServer Faces is a standard JSF is standardized via the JCP (Java Community Process). Since JSF 1.2 it is part of the Java Enterprise Edition. Slide 14
Main concepts within JSF Bean management Navigation rules / definition of page flows Conversion and input validation Event handling Lifecycle... Slide 15
And: Powerful UI components Slide 16
Our example web application Small web application for a company s inventory management. You can enter new inventory data. You can remove items from the inventory list. And of course you can see reports on your inventory. Two solutions JSF 1.2 and JSPs JSF 2.0 and Facelets Slide 17
Agenda What is reporting? Why do we need it? The JSF example application Introduction to reporting engines Overview Eclipse BIRT JasperReports Integration into JSF Eclipse BIRT JasperReports Conclusion Slide 18
Reporting engines Do you need a reporting engine? Fine, how many millions do you have as budget? That s not true any more. There are plenty of good OpenSource solutions available. Slide 19
Reporting and OpenSource Quick Google search: More than 50 projects about reporting Big and very well-know ones (and the ones where I have some personal experience ) Eclipse BIRT JasperReports Slide 20
Agenda What is reporting? Why do we need it? The JSF example application Introduction to reporting engines Overview Eclipse BIRT JasperReports Integration into JSF Eclipse BIRT JasperReports Conclusion Slide 21
The Eclipse BIRT project BIRT = Business Intelligence and Reporting Tools Top level project within Eclipse Foundation OpenSource Offers a framework for reporting and business intelligence for web applications and rich clients Slide 22
Eclipse BIRT: History Founded by Actuate Corporation In 2004: Moved to the Eclipse Foundation, then became OpenSource Still an active community http://www.birt-exchange.com Actuate offers professional services and additional products Slide 23
Eclipse BIRT: General overview Slide 24
Eclipse BIRT: IDE Slide 25
Part 1: Creating a BIRT report definition 1. Create a BIRT report project 2. Assign a datasource 3. Create a dataset 4. Create your report (including chart) 5. Preview and test your report 6. View it in pdf/html/ Slide 26
BIRT Report definitions BIRT reports are stored in *.rptdesign files Xml file Report files can be included in applications A runtime engine is needed to display the reports Slide 27
Part 2: Viewing the results Slide 28
Demonstration of BIRT Slide 29
Agenda What is reporting? Why do we need it? The JSF example application Introduction to reporting engines Overview Eclipse BIRT JasperReports Integration into JSF Eclipse BIRT JasperReports Conclusion Slide 30
JasperReports According to the Website: JasperReports is the world's most popular open source Java reporting library Open Source Company behind : JasperSoft Part of the JasperSoft Business Intelligence Suite (commercial) Completely written in Java Can generate Pdf, Html, Xls, CSV, Xml, Slide 31
Based on existing libraries Various Jakarta Commons libs Jakarta POI and JExcel API itext JFreeChart Slide 32
JasperReports additional tools ireport Designer (free) JasperServer JasperAnalysis (OLAP) JasperETL Slide 33
JasperReports report template - Again XML - To be more precisly JRXML <jasperreport name="simple_report"> <detail> <band height="20"> <statictext> <reportelement x="180" y="0" width="200" height="20"/> <text><![cdata[hello World!]]></text> </statictext> </band> </detail> </jasperreport> Slide 34
JasperReports previewing the template - In the download package, there are some ant tasks to preview a template ant viewdesignxml - net.sf.jasperreports.view.jasperdesigner - Small swing application which displays the jrxml files Slide 35
From *.jrxml to *.jasper - Report files are compiled to *.jasper files Slide 36
Generating a Jasper report To produce reports, you need at least: - Report template (compiled) - Parameters - Data source Result is a document (pdf, html, ) Slide 37
ireport report designer for JasperReports Visual report designer Free and Open Source Available for various operating systems Slide 38
ireport IDE Slide 39
Demonstration of JasperReports Slide 40
Agenda What is reporting? Why do we need it? The JSF example application Introduction to reporting engines Overview Eclipse BIRT JasperReports Integration into JSF Eclipse BIRT JasperReports Conclusion Slide 41
Integrating BIRT BIRT-Runtime (1) WebViewer Webapplication (2) WebViewer and Taglib (3) BIRT APIs Slide 42
WebViewer web application 1. Deploy birt.war 2. Add commons-logging 3. Copy report file into the birt-folder 4. Add your database driver (library) 5. Call a birt url http://localhost:8080/birt/frameset? report=myreport.rptdesign Slide 43
WebViewer - Options Frameset Fully fledged report Menus Paging Run Only report without decoration Slide 44
Combination with JSF? IFrame When clicking on a button or link, you can open an overlay iframe Popup Open a new popup window where the report is created Slide 45
WebViewer and taglib 1. Create a new web application 2. Include birt.tld (e.g. WEB-INF/tlds) 3. Edit web.xml to let your tld know 4. Include necessary jars in your WEB-INF 5. Create JSP-pages using the BIRT-taglib <birt:viewer id="birtviewer" reportdesign="reportforjsf.rptdesign" format="html" ishostpage="false" baseurl="/birt"> </birt:viewer> Slide 46
JSF tags provided by JBoss SEAM Using the SEAM framework and JBoss Tools, there are specialized JSF tags for including BIRT <p:birt designtype="embed" masterpage="false" embeddable="true" designname="rpy.rptdesign" > <p:param name="myparam" value="myvalue"/> </p:birt> Slide 47
Combination with JSF? Create a JSF application Do the same steps as mentioned before Write a JSF page with included JSP tags - Combine JSF and JSP tags - or use the tags provided by SEAM Slide 48
Using the BIRT APIs It is also possible to use the BIRT APIs The API is very powerful You can control nearly everything by the APIs By using the APIs, you can create a report within your application Slide 49
Using the BIRT APIs - example Platform.startup( config ); IReportEngineFactory factory =...; engine = factory.createreportengine(config); IReportRunnable design = null; design = engine.openreportdesign("jsf.rptdesign"); IRunAndRenderTask task = engine.createrunandrendertask(design); HTMLRenderOption options = new HTMLRenderOption(); options.setoutputstream( resp.getoutputstream() ); options.setoutputformat( "html" ); task.setrenderoption(options); task.run(); Slide 50
Combination with JSF? Redirect from a JSF call to a BIRT servlet Use Facelets to include a servlet into a page Within the servlet, use the API to generate your report Slide 51
Agenda What is reporting? Why do we need it? The JSF example application Introduction to reporting engines Overview Eclipse BIRT JasperReports Integration into JSF Eclipse BIRT JasperReports Conclusion Slide 52
Jasper and JSF Create an output file (pdf, xls,..) and display it Building a servlet which generates html Popup / IFrame Slide 53
Jasper and JSF byte[] bytes = JasperRunManager.runReportToPdf(... ); HttpServletResponse response = (HttpServletResponse)facesContext.getExternalContext().getResponse(); ServletOutputStream servletoutputstream = response.getoutputstream(); servletoutputstream.write(bytes, 0, bytes.length); servletoutputstream.close(); FacesContext.getCurrentInstance().responseComplete(); Slide 54
Agenda What is reporting? Why do we need it? The JSF example application Introduction to reporting engines Overview Eclipse BIRT JasperReports Integration into JSF Eclipse BIRT JasperReports Conclusion Slide 55
Conclusion There are some really good (Open Source) reporting engines available Both BIRT and Jasper separate the design phase from the runtime phase For viewing reports in a web page there are various ways to do this There is no real integration into JSF, but several ways to realize this yet. But still: It works!!! Slide 56
Any questions? German pages: www.jsf-forum.de English pages: www.jsf-portlets.net Or send an email to andy.bosch@jsf-portlets.net Slide 57