Using the BIRT Report Viewer

Overview

If you are using the 2.2.x Birt Viewer please see this page.

The sample BIRT viewer is optimized for use within Eclipse for the preview operation. When used outside Eclipse, it simply acts as an example of the application you might build to run and view reports. Your report viewer application must be in Java so that it has access to the BIRT engine. The viewer can also be deployed as an Eclipse plugin in an RCP application.

The Viewer performs three distinct operations, of which one is internal and not visible to your application:

  • Create a frameset based viewer that interacts with the servlet using AJAX to support more features.
  • Given a set of report parameter values, run a report and return the output as either HTML or PDF.
  • Retrieve an embedded image, or an image of a chart within the report. (Internal operation.)

You can use a full-feature Viewer frameset that handles parameter entry, Table of Contents, export to CSV and HTML pagination. Or, you can supply the parameter values and simply run the report to produce a simple HTML or PDF output page.

Viewer Operations

The BIRT viewer provides a number of URLs that control its behavior. The Viewer provides two modes of operation as given by two servlet mappings.

Operation Description
frameset Display a frameset that contains the report and additional AJAX components for retrieving Table of Contents, exporting to CSV, parameter entry and paging controls.
run Runs the report and displays the output as a stand-alone HTML page, or as a PDF document.

The servlet mapping names are case sensitive.

Run a Report

The run servlet mapping runs a report given a set of report parameters, and returns the report as an HTML page or PDF document. This servlet mapping does not provide a frameset. Use this option if you want the report to appear as a stand-alone page or if PDF output is required. Parameters must be handled in one of three ways:

  • The report requires no report parameters.
  • Your application already knows the values of the parameters (perhaps from a server session), and passes them along.
  • Your application has created a parameter page specifically for the report.

Birt 2.1 RC3 or Later Runtime Note:

  • If your report has a required parameter with no default value, the parameter entry screen will be displayed automatically.

The run report URL is of the form:

http://sitePrefix/birt-viewer/run?option1=value1;option2=value2;...

See below for a list of available viewer command options.

Viewer Frameset

The frameset command provides additional UI to work with a report. Use this URL when your report contains parameters, and you want the Viewer to display a UI so the user can enter parameter values. Using the frameset command also allows for HTML pagination.

The frame-based viewer displays a frameset that contains the report and controls for the following functions:

  • Table of Contents - Use this navigate reports. Selecting a link in a multi-page report will automatically load the desired page.
  • Run Report - Use this control to enter parameters and execute the report.
  • Export Data - This control prompts the user to select what report data should be exported to CSV.
  • Page Controls - Navigate paginated HTML report output.

The parameters dialog displays a form for entering the parameters (if any) for a report. It contains a Run Report button that runs the report. The report then appears in the report frame . The user can refine the report simply by modifying parameters in the parameter frame and again by clicking Run Report.

The viewer URL is of the form:

http://sitePrefix/birt-viewer/frameset?option1=value1;option2=value2;...

See below for a list of available command options. The command options allow you to control which of the three frames appear in the resulting web page.

When you issue this command, the viewer will do one of two things:

  • Run and display the report if any of the following conditions are true.
    • The report has no parameters
    • All parameters have supplied default values.
    • All parameters have allowNull property checked
  • or
  • Display the parameter page and ask you to enter parameters. You can then click the Run Report button to run the report.

Viewer Command Options

The run and the frameset Viewer operations both take a set of options which include report parameters. Report parameters are defined within the report design. They appear in the URL using their internal names, not display names. Viewer options pass information to the BIRT Viewer web app. Viewer options start with a double underscore to differentiate them from report parameters. Option names and values must be encoded for use in a URL. For example:

http://localhost:8080/birt-viewer/run?__report=report%5CSalesInvoice.rptdesign&OrderNumber=10010

In the above:

  • http://localhost:8080/ – The URL (including port) for your installation of the app server.
  • /birt-viewer/ – The name of the BIRT Viewer servlet.
  • run – The servlet mapping for running a report.
  • report%5CSalesInvoice.rptdesign – Relative file system path of the report to run. The name is relative to the web app directory in which the birt-viewer was installed.
  • OrderNumber=10010 – The name and value of a report parameter as defined in the report design.

List of Options

The available viewer options include:

Option Description Values Default frameset run
__format The output format html or pdf html N Y
__isnull Identifies that a report parameter has a null value Parameter name None. Required. N Y
__locale Report locale Java locale value such as en, en-us or ch-zh. JVM locale Y Y
__report The path to the report design.   None. Required. Y Y
__document The path to the report document.   None. Required. Y N
reportParam Report parameter. As specified in the report design. As specified in the report design. Y Y

Case-Sensitivity

Case-sensitivity of the options varies:

  • Viewer option names and values are case-insensitive.
  • Report parameter names are case-sensitive: they must match the name as defined in the design.
  • The file name case sensitivity is defined by your operating system.

If the URL contains a misspelled option name, or the name of report parameters are in the wrong case, then the Viewer silently ignores the parameter.

The __format Option

The type of output to produce: either html or pdf. Values are case insensitive. If a value other than pdf is provided, then the HTML format is produced.

The __isnull Option

Report parameters can take a value, or can be null. (Here "null" means the database definition: the value is unknown.) By definition, date and numeric report parameters have a null value if the report parameter is provided in the URL, and the value is blank. However, string report parameters have an ambiguity: is an empty value to be considered blank (a string whose value is ""), or null? Since blank is used more often, BIRT interprets an empty report parameter value as blank. To say a string parameter is is null, just write:

__isnull=yourParam

While this option is primarily for string report parameters, it works just as well for other report parameter types as well. See the Report Parameters section below for additional details.

The __locale Option

Use the __locale option to specify both the locale for report parameter values, and the locale for the report output. The locale must be a valid Java locale such as en-us, etc. as specified in the Sun Java locale guidelines. If you do not specify a locale, it defaults to the locale set in the Java virtual machine (JVM.)

Values are case insensitive.

The __report Option

The __report Option names the report design to run. It can be an absolute or relative file name. If relative, the following search rules are used.

  • If name is absolute, use it directly.
  • If BIRT_VIEWER_DOCUMENT_FOLDER is set in the web.xml, use this value as the base for the relative name.
  • If BIRT_VIEWER_WORKING_FOLDER is set in the web.xml, use this value as the base for the relative name.
  • Otherwise, use the viewer web app's directory as the base for the relative name.

The __document Option

The __document Option names the report document to run with the frameset mapping. This file is the intermediate file when run and render are separate phases. It can be an absolute or relative file name. If relative, the following search rules are used. If the __document parameter is used without the __report parameter and existing report document can be rendered.

  • If name is absolute, use it directly.
  • If BIRT_VIEWER_DOCUMENT_FOLDER is set in the web.xml, use this value as the base for the relative name.
  • If BIRT_VIEWER_WORKING_FOLDER is set in the web.xml, use this value as the base for the relative name.
  • Otherwise, use the viewer web app's directory as the base for the relative name.

Report Parameters

Report parameters can be Boolean, Number, Date, Float or String. The values are defined as follows:

Data Type Value Encoding Notes
Boolean true, false Must use the value true for a true value, all other values (including 1) are treated as false. (Uses the Java Boolean.parse() method for parsing.) Values are case-insensitive.
Number Floating point number with a locale-specific decimal separator. Must not include a thousands separator, or extra characters such as a currency symbol. Uses the Java java.text.DecimalFormat class to parse the number.
String None  
Date Locale-specific date format. Uses the Java java.text.SimpleDateFormat class to parse the date.

Report Parameter Value

The rules for a given parameter foo are determined by the first rule below that takes effect:

  • If __isnull=foo appears in the URL, foo's value is null.
  • If foo=mumble appears in the URL, foo's value is mumble.
  • If foo= appears in the URL, foo's value is blank if it is a string, and null if it is a number or date.
  • If foo has a default value, foo's value is that default value.
  • Otherwise, foo's value is blank for string or null for number and date.

Value Checking

The report definition provides two properties for report parameters that influence parameter validation. First, the allowNull property determines if a report parameter can be null. If a report parameter has a null value, but the allowNull property is false, then the BIRT report engine will raise an error.

Second, string report parameters have a allowBlank property. If report parameter has a blank value, and allowBlank property is false, then the BIRT report engine will raise an error.

Error Reporting

If an error occurs during the operation, an error page will appear.