BIRT Developer Center Download

BIRT with JSF

Using BIRT and Actuate with JavaServer Faces (JSF)


JSF 1.x using jsf4birt

Overview

The jsf4birt component library supports the rendering of BIRT-based reports on pages within JavaServer Faces (JSF) Web applications. Report viewers implemented as JSF components using this library can then be easily adjusted through tag attributes. There are two components. A BIRT wrapper and an Actuate wrapper. The BIRT wrapper component displays BIRT reports created in BIRT’s Eclipse design tool. This component uses the BIRT runtime API. The component calls the appropriate part of the API from the BIRT runtime to get generated HTML code to put on the page. Everything is done on the server side following the usual JSF lifecycle processing. The Actuate wrapper component loads reports from an installed Actuate server. The component uses the Actuate JavaScript API to load and run reports on the page using client-side processing.

Download and Install the jsf4birt Component Library

Download

Download the Exadel jsf4birt component library at the link below.



The jsf4birt wrapper depends on the BIRT Runtime in order to render and display BIRT report designs. The current version of the jsf4birt wrapper will work with either BIRT 2.3.2 or BIRT 2.5.2. You should also download a BIRT Report Designer in order to create new BIRT report designs.



Install

The download ZIP file contains a comprehensive installation guide but the basic steps are:

Installing the jsf4birt component

  • Uncompress the ZIP containing the jsf4birt wrapper and read the license.
  • Navigate to the TLDocs folder and open index.html to find the documentation


The next few steps assume you have a web application configured for JSF and Facelets that you are going to be adding support for the jsf4birt wrapper. If you don't, skip the rest of the install steps and just download a complete demo web application as a WAR file from here

  • Copy all the JARs from the BIRT Runtime /ReportEngine/lib directory into your application's /WEB-INF/lib directory.
  • Create a directory named platform in your WEB-INF folder.
  • Copy the /Report Engine/plugins and /ReportEngine/configuration directories to the new 'platform' directory you just created.
  • Copy the jsf4birt.jar to your /WEB-INF/lib directory.


Download and install BIRT iHub Trial

To use the actuateWrapper, you will need to download and install a trial version of the BIRT iHub.

Instructions to Download and Install BIRT iHub

Testing the jsf4birt component

Creating a simple BIRT Design

Launch the BIRT Designer that you downloaded in a previous step.Download the Exadel jsf4birt component library from the marketplace at the link below.

  • Switch to the Report Design perspective
  • File | New | Report Design - Just pick the blank template and name it whatever you want.
  • Right-click on the report and insert a Label. - Just keep it simple at first by not including any external resources or database connections.
  • Save the report design and copy the rptdesign file to a folder in your web application


Testing the jsf4birt:birtWrapper

  • Add the following namespace attribute to your HTML tag
    xmlns:birt="http://jsf4birt.components"
  • Use the birtWrapper similar to below
    <birt:birtWrapper id="report" reportDesign="/Reports/birt_report.rptdesign">
    <f:param name="MyParam" value="Something" />
    </birt:birtWrapper>
  • Below is an example BIRT Report integrated as a JSF component.
BIRT-with-JSF-example-report

Testing the jsf4birt:actuateWrapper

  • Add the following context parameters to the web.xml so you application knows where to find the Actuate iHub.
    <context-param>
    <param-name>actuate.serverUrl</param-name>
    <param-value>http://localhost:8900/iportal</param-value>
    </context-param>

    <context-param>
    <param-name>actuate.serverLogin</param-name>
    <param-value>administrator</param-value>
    </context-param>

    <context-param>
    <param-name>actuate.serverPassword</param-name>
    <param-value></param-value>
    </context-param>

    <context-param>
    <param-name>org.eclipse.birt.configPath</param-name>
    <param-value>configuration/config.ini</param-value>
    </context-param>
  • Add the following namespace attribute to your HTML tag
    xmlns:birt="http://jsf4birt.components"
  • Use the actuateWrapper similar to below
    <birt:actuateWrapper id="report" reportName="/Home/administrator/Customer Dashboard.rptdesign"
    runWhenRendered="true">
    <f:param name="MyParam" value="Something" />
    </birt:actuateWrapper>
  • Below is an example BIRT Report from the BIRT iHub integrated as a JSF component.
BIRT-with-JSF-iHub-report

JSF 2.x

This section works with JSF 2.0 with BIRT example that can be found in the devshare. The requirements to run this example are the JSF 2.0 and BIRT 3.7.2 jars.

The sample report that it’s packaged with it takes a country as a parameter then displays all of the customers that match and a chart that shows credit limit by country.birt2jsf.java is a class that I created to generate the report. Instead of writing it to an HTML file I?m using a ByteArrayOutputStream and set the output stream to this object. This allows me to display the HTML report in the same page as my xhtml.

// set render options including output type
PDFRenderOption options = new PDFRenderOption();
ByteArrayOutputStream outs = new ByteArrayOutputStream();
options.setOutputStream(outs);
options.setOutputFormat("html");
task.setRenderOption(options);


BirtBean.java is the managed bean that gets the value of the parameter that we would like to pass to the report. I do this with the getter and setter methods.

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}


setName() is called when the command button is pressed in page-a.xhtml. It takes the value that the user has given us and stores it in the bean for later use. getName() is called whenever we are calling birtBean.name and will return the value of name. This allows us to output what the user has given as a parameter in the input text when the page is refreshed with the newly generated report.

Also in BirtBean.java is getReport() this is another getter method that I use to call the birt2jsf class and return the outputstream.

public String getReport() {
birt2jsf report = new birt2jsf( );
String reportHTML = null;
try {
reportHTML = report.executeReport(name);

} catch (EngineException e) {
e.printStackTrace();
}
return reportHTML;
}


When the page is first loaded it will only show the input text. The report is there, I?ve set it to not be visible if no parameter has been passed to it. To see this in action type France and click view report.

If everything went well then you should see JSF and BIRT working together smoothly like the screen shot below. Where enter country, input text, and view report are JSF 2.0 tags and the report is being viewed by using the JSF h:outputText tag

<h:outputText value="#{birtBean.report}" escape="false"/>


BIRT-with-JSF-screenshot

Thanks for reading my blog and if you have any comments or questions feel free to do so below.

To download the example visit the devshare entry