JBoss.orgCommunity Documentation
Version: 1.0.0.GA
Copyright © 2008, 2009 JBoss, a division of Red Hat
August 2008
BIRT plugin is an Eclipse-based open source reporting system for web applications based on Java and J2EE. BIRT consists of two main components: a report designer based on Eclipse, and a runtime component that can be added to your app server. BIRT also offers a charting engine that lets you add charts to your own Web application.
With the help of BIRT you can generate a great number of reports to be used in your application:
Lists
Charts
Crosstabs, or cross-tabulation, or matrix
Letters and Documents
Compound Reports
You can find more detailed information on the BIRT plugin, its report types and anatomy on the BIRT Homepage.
To understand the basic BIRT concepts and to know how to create a basic BIRT report, refer to the Eclipse BIRT Tutorials. What extensions JBoss Tools provides for Eclipse BIRT you'll find out in the next sections.
This reference guide describes the one module of the JBoss Tools project which performs the integration with BIRT. The integration includes the following functionalities:
Hibernate ODA driver that includes a dialog to create HQL queries with syntax-highlighting, content-assist, formatting as well as other functionalities available in the HQL editor. There is also a possibility to add parameters.
possibility to add JBoss BIRT functionality to the standard Seam web project
BIRT JSF/Seam control
deployment of BIRT reports within web projects (Seam, JSF, etc.)
To enable JBoss Tools integration with BIRT you are intended to have the next:
Eclipse with JBoss Tools installed (how to install JBoss Tools on Eclipse, what dependences and versions requirements are needed reed in the JBoss Tools Installation section)
BIRT Report Designer (BIRT Report Designer 2.3.2 you can download from Eclipse downloads site)
BIRT Web Tools Integration ( BIRT WTP Integration 2.3.2 you can download from Eclipse downloads site)
Versions of BIRT framework and BIRT WTP integration should be no less than RC4 in order to the BIRT facet works correctly.
All JBoss Developer Studio/JBoss Tools release documentation you can find athttp://docs.jboss.org/tools in the corresponding release directory.
The latest documentation builds are available at http://download.jboss.org/jbosstools/nightly-docs.
In this chapter you'll know how to create a Seam web project with BIRT capabilities included.
You are supposed to have Seam runtime and JBoss Application Server downloaded and extracted somewhere on you hard drive.
We usedJBoss Seam 2.0.1 GA and JBoss Application Server 4.2.2 GA in examples of this guide.
First, open Seam perspective by going to Window > Open Perspective > Other > Seam. To create a new Seam Web project follow to File > New > Seam Web Project (or File > New > Other > Seam > Seam Web Project if you are not in the Seam perspective).
On the first wizard page enter the project name, then specify the target runtime and target server. In the Configuration section click Modify to configure the project facets.
Choose the 2.0 version of the Seam facet and enable the Birt Reporting Runtime Component facet.
Or you can just choose the JBoss BIRT Integration Web Project configuration.
Next three pages are filled out with defaults, just leave them through by pressing Next. On the Seam Facet page you should specify the Seam runtime and Connection profile.
Hit Finish to create the project with Birt functionality enabled.
The JBoss BIRT Integration feature contains the BIRT tag that allows the user to add a BIRT report to an .xhtml file:
<p:birt xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:p="http://jboss.com/products/seam/birt" designType="run" format="pdf" designName="test.rptdesign" title="JBoss Birt Test"> </p:birt>
Let's look how it works.
Create in the Web Content folder three .xhtml pages with the following content:
birttests.xhtml:
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" template="layout/template.xhtml"> <ui:define name="body"> <h:messages globalOnly="true" styleClass="message"/> <rich:panel> <f:facet name="header">Welcome to JBoss BIRT!</f:facet> <ul> <li><s:link view="/testbirt.xhtml" value="Test Birt" /></li> <li><s:link view="/testbirt1.xhtml" value="Test Birt 1" /></li> </ul> </rich:panel> </ui:define> </ui:composition>
testbirt.xhtml:
<p:birt xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:p="http://jboss.com/products/seam/birt" designType="run" format="pdf" designName="test.rptdesign" title="JBoss Birt Test"> <p:param name="sample" value="sample param"/> </p:birt>
testbirt1.xhtml:
<p:birt xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:p="http://jboss.com/products/seam/birt" designType="frameset" designName="test1.rptdesign" title="JBoss Birt Test"> </p:birt>
Now start the application server by clicking the Start option in the context menu of the server in the JBoss Server View (if the view isn't open go to Window > Show View > Other > JBoss Server View). Try the tests out by accessing http://localhost:8080/hellobirt/birttests.seam in your web browser.
Now if you click Test Birt you should see the following .pdf file:
After clicking Test Birt 1 the next page is displayed:
Put the test param as Sample Parameter value, specify the maximum possible Customer Number as 1001, for instance, and then press Ok. You'll see the following BIRT report:
The BIRT tag recognizes most of the parameters described on the BIRT Report Viewer Parameters page. The attributes of the BIRT tag don't contain the "__" prefix.
The param tag describes report parameters (see the listing for the testbirt.xhtml above). It supports the following attributes:
name - the parameter name (required)
value - the parameter value (required)
isnull - specifies that a report parameter has a null value (optional)
islocale - specifies whether the parameter is localized (optional)
These tags are defined in the org.jboss.birt.core/resources/jboss-seam-birt.jar library that contains source.
It is also possible to embed a BIRT report in some Seam .xhtml page. See how it may be done:
Example:
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" xmlns:b="http://jboss.com/products/seam/birt" template="layout/template.xhtml"> <ui:define name="body"> <h:messages globalOnly="true" styleClass="message" id="globalMessages"/> <rich:panel> <f:facet name="header">Products</f:facet> <b:birt designType="embed" designName="ProductCatalog.rptdesign" embeddable="true" masterpage="false"/> <div style="clear:both"/> </rich:panel> <div class="actionButtons"> <s:button view="/ProductsEdit.xhtml" id="edit" value="Edit"/> <s:button view="/#{empty productsFrom ? 'ProductsList' : productsFrom}.xhtml" id="done" value="Done"/> </div> </ui:define> </ui:composition>
See the result in a Browser:
The JBoss BIRT Integration feature includes the Hibernate ODA Data Source completely integrated with Hibernate Tools. You can use it in the way you use any of BIRT ODA drivers. Let's perform simple actions that demonstrate it.
First, run the Seam Generate Entities action (You can access it from File > New > Seam Generate Entities in the Seam perspective. More details on the Seam Generate Entities read in our Seam Dev Tools Reference guide). This action will create a Hibernate Console configuration.
Before performing Seam Generate Entities, you should have a connection profile adjusted and connected to a database. How to do this see in the CRUD Database Application chapter of the Seam Dev Tools Reference guide.
Next add a new BIRT report. To do that navigate to File > New > Other > Business Intelligence and Reporting Tools > Report. In the New Report wizard enter the report name, for instance testHibernateOda.rptdesign, then click Finish.
Now switch to the Report Design perspective.
In the Data Explorer View right-click the Data Source node and choose New Data Source.
In the wizard select Hibernate Data Source and give it a proper name, HbDataSource for instance. Hit Next.
On the next wizard page leave everything as it is, just press the Test Connection button to verify the connection is successful.
Click Ok and then Finish to complete.
Now let's add a Hibernate ODA dataset. To do that you should bring up the New Data Set wizard. In the Data Explorer View right-click the Data Set node and select New Data Set.
In the Data Set Name section specify the name. Let's it be HbDataSet.
Next you'll be prompted to define the query for this data set. To validate the entered query you can press the Test query button. All the HQL features like syntax highlighting, content assist, formatting, Drag and Drop, etc., are available to you here.
Next the output columns will be displayed. It's possible to edit them here.
To preview the results of the defined query click the Preview Results item.
So far you have the Hibernate data source and data set defined. Now you can create a BIRT report using this data source and data set.
If you don't know how to do this we suggest that you refer to the Eclipse BIRT Tutorial.
If you switch to the Preview tab, it will run your report and show the output.
You can also use parameters within the Hibernate ODA driver.
Again, to preview the results switch to the Preview Results item.
When everything is configured correctly you will be able to view/render the designed reports in your Seam (or any other) Web application.
You can deploy a report by adding an action button to the Seam's CRUD .xhtml file.
As you can see on the figure you should have the testHibernateOda.xhtml file. It's content should be the following:
<p:birt xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:p="http://jboss.com/products/seam/birt" designType="run" format="pdf" designName="testHibernateOda.rptdesign" title="JBoss Birt Test"> </p:birt>
Next run the Seam page with embedded report on the server by right-clicking the file and going to Run > Run on Server.
After clicking the BIRT PDF Report button, you should see the following report:
Thus, a Seam project that includes the BIRT facet can be deployed as any project. If you define the Hibernate ODA driver, the JBoss BIRT engine will use JNDI URL that has to be bind to either Hibernate Session Factory or Hibernate Entity Manager Factory. If you don't specify the JNDI URL property, our engine will try the following JNDI URLs:
java:/<project_name>
java:/<project_name>EntityManagerFactory
When creating a Seam EAR project, Hibernate Entity Manager Factory is bound to java:/{projectName}EntityManagerFactory. All you need to do is using the Hibernate Configuration created automatically. You can use default values for the Hibernate Configuration and JNDI URL within the BIRT Hibernate Data Source.
When using a Seam WAR project, neither HSF nor HEMF aren't binded to JNDI by default. You has to do this manually. For instance, HSF can be bound to JNDI by adding the following property to the persistence.xml file:
<property name="hibernate.session_factory_name" value="java:/projectname"/>
And you can use java:/projectname as the JNDI URL property when creating a BIRT Hibernate Data Source.
If you want to test this feature using PDE Runtime, you need to add osgi.dev=bin to the WebContent/WEB-INF/platform/configuration/config.ini file.
In conclusion, the main goal of this document is to get you know with a full featureset that JBoss BIRT Tools provide. Thus if you have some questions, comments or suggestions on the topic, please feel free to ask in the JBoss Tools Forum. You can also influence on how you want to see JBoss Tools docs in future leaving your vote on our page here.