JBoss.orgCommunity Documentation

Birt Plugin Integration Reference Guide

Olga Chikvina

Version: 1.0.0.GA

August 2008


1. Introduction
1.1. What is BIRT?
1.2. JBoss BIRT Integration Functionality Overview
1.3. Other Relevant Resources on the Topic
2. Adding BIRT Functionality to Standard Seam Web Project
2.1. Creating Seam Web Project with Birt Facet
2.2. Integration with Seam
3. Hibernate ODA Data Source
4. BIRT Reports Deployment

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.

Tip:

We usedJBoss Seam 2.0.1 GA and JBoss Application Server 4.2.2 GA in examples of this guide.

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:

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.

Tip:

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 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.

Note:

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.