Birt 4 with Seam 2.3 - a minimun approach

Version 1

    Birt is a powerful report engine and JBoss Seam is an excellent framework to improve development productivity.

    One can use seam-gen or JBoss Tools in order to integrate these two great tools, unfortunately it will generate a lot of stuff, some of them unnecessary to certain scenarios.

    The objective of this tutorial is configure a Seam Web Application to use Birt Report with minimal use of jars and configuration.

    The versions used in this tutorial are  Birt 4.3.2 and Seam 2.3 . Jboss Tools is used to help the creation of a Seam Web Application.

     

    The first step is to Create and deploy Seam Web Project. The Birt Facet Project must NOT be selected since not all the Birt jars and configurations are desired.

     

    The second step is to copy only the necessary jars from birt runtime, which can be downloaded  from http://download.eclipse.org/birt/downloads/

     

    The necessary jars from birt-runtime-4_3_2/ReportEngine/lib to run the test.rptdesign are :

     

    1. com.ibm.icu_50.1.1.v201304230130.jar
    2. js.jar
    3. org.apache.batik.css_1.6.0.v201011041432.jar
    4. org.apache.batik.util_1.6.0.v201011041432.jar
    5. org.apache.commons.codec_1.3.0.v201101211617.jar
    6. org.eclipse.birt.runtime_4.3.2.v20140225-1404.jar
    7. org.eclipse.core.runtime_3.9.100.v20131218-1515.jar
    8. org.eclipse.datatools.connectivity_1.2.11.v201401230755.jar
    9. org.eclipse.datatools.connectivity.oda_3.4.2.v201311051159.jar
    10. org.eclipse.equinox.common_3.6.200.v20130402-1505.jar
    11. org.eclipse.equinox.registry_3.5.301.v20130717-1549.jar
    12. org.eclipse.osgi_3.9.1.v20140110-1610.jar
    13. Tidy.jar

     

    Also these two Seam jars are required :

    1. jboss-birt-servlet.jar
    2. jboss-seam-birt.jar

     

    They can be downloaded* from :

    https://github.com/jbosstools/jbosstools-birt/raw/master/plugins/org.jboss.tools.birt.core/resources/jboss-birt-servlet.jar

    https://github.com/jbosstools/jbosstools-birt/raw/master/plugins/org.jboss.tools.birt.core/resources/jboss-seam-birt.jar

    *More information about this : Can't run the JBoss Birt integration sample

     

    The third step is to edit the web.xml and add this :


      <!-- ================================================================== --> 
      <!-- BIRT Minimum Configuration by Bussard                              --> 
      <!-- ================================================================== -->   
      <servlet> 
        <servlet-name>JBoss BIRT Servlet</servlet-name> 
        <servlet-class>org.jboss.tools.birt.servlet.JBossBirtServlet</servlet-class> 
      </servlet> 
    
      <servlet-mapping> 
        <servlet-name>JBoss BIRT Servlet</servlet-name> 
        <url-pattern>/embed</url-pattern> 
      </servlet-mapping>   
    
    

     

    Copy birt-runtime-4_3_2/WebViewerExample/test.rptdesign to your project WebContent and create a new xhtml page like this:

     

    <!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.org/schema/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">
    
      <b:birt designType="preview"
              embeddable="true"
              format="pdf"
              designName="test.rptdesign"
              title="Test" >
          <b:param name="sample" value="Report Test " />
      </b:birt>
      </ui:define>
    </ui:composition>
    
    
    
    
    
    
    
    
    
    
    
    

     

    It should display the test report.

     

    The fourth step is export to other formats like PDF and XLS. This task will require either create a servlet or use the ViewerServlet provided by the birt runtime at the WebViewerExample, the last method will be used here.

     

    The WebViewerExample is located in birt-runtime-4_3_2/WebViewerExample/WEB-INF/lib folder and the jars to copy are:

    1. viewservlets.jar
    2. axis.jar
    3. commons-discovery-0.2.jar

     

    The web.xml needs these configuration entries :

     

      <servlet> 
        <servlet-name>ViewerServlet</servlet-name> 
        <servlet-class>org.eclipse.birt.report.servlet.ViewerServlet</servlet-class> 
        <load-on-startup>1</load-on-startup> 
      </servlet> 
    
      <servlet-mapping> 
        <servlet-name>ViewerServlet</servlet-name> 
        <url-pattern>/run</url-pattern> 
      </servlet-mapping> 
    
    

     

    This imp.xml runs the report if everything is Ok :

     

    <b:birt xmlns:ui="http://java.sun.com/jsf/facelets" 
            xmlns:s="http://jboss.com/products/seam/taglib" 
            xmlns:b="http://jboss.com/products/seam/birt"
      designType="run"
      format="#{!empty formato ? formato : 'pdf'}"
      designName="test.rptdesign"
      title="Test" >
      <b:param name="navigationbar" value="true" />
    </b:birt>
    
    
    
    
    
    
    
    
    
    
    
    

     

    It uses this imp.page.xml:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <page xmlns="http://jboss.com/products/seam/pages"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd">
         <param name="formato"/>
    </page>
    
    
    
    
    
    
    
    
    
    
    
    

     

    And the link to print a report can be like this:

     

    <s:link value="Pdf Export"
      view="/imp.xhtml"
      target="_blank">
      <f:param name="formato" value="pdf"/>
    </s:link>
    
    
    
    
    
    
    
    
    
    
    
    

     

    The fifth step is connect to a database with JDBC or JNDI. To do that, this jars from birt-runtime-4_3_2/ReportEngine/lib are required:

     

    1. org.eclipse.datatools.connectivity.oda.consumer_3.2.6.v201305170644.jar
    2. org.apache.xerces_2.9.0.v201101211617.jar

     

    So is necessary to configure a data source for a report as a JDBC :

    Birt 4 with Seam 2.3-01.jpg

     

    Set a jdbc driver:

    Birt 4 with Seam 2.3-02.jpg

     

    And finally set the connections' properties

    Birt 4 with Seam 2.3-03.jpg

     

    Other scenarios will need different jars, but this dependencies can be easily found.