Example Module

This howto is supported by an example module which includes the simple report described in the examples of this document. The report is named Product Simple Report and prints in PDF a list of Products that can be filtered by Product Category.

Report Definition in Application Dictionary

Process Definition

Set Report (Using JR Templates). This value will display the Report Definition tab.

Action Handler

If none is set when the UI Pattern is selected the org.openbravo.client.application.report.BaseReportActionHandler is set.

The BaseReportActionHandler is the default action handler to use in reports. In case you desire to make some Java validations or include some extra parameters that are not defined in the Process Definition parameters tab it is possible to use a custom Action Handler that extends the BaseReportActionHandler.

Parameter Definition

In the Parameter tab are added all the parameters that are needed to filter the results of the report. Their values are handled by the BaseReportActionHandler and sent to Jasper Reports as parameters. This parameters need to be defined in the JR template with the same name as the column name.

When the filter parameter is a Selector reference the value is sent as a JSONOBject that includes 2 keys:

value with the id of the selected BaseOBObject to be used in the SQL query

identifier with the readable identifier that can be used to print in the report the filter values.

In case of Multiple Selectors the JSONObject includes 4 keys:

values with a JSONArray including all the selected ids.

identifiers with a JSONArray including all the identifiers.

strValues with a comma separated String with all the selected ids that can be used in a SQL IN clause.

strIdentifiers with a comma separated String with all the selected identifiers.

In the Jasper Template the parameter has to be defined using the class org.codehaus.jettison.json.JSONObject.
In the example it is set a Product Category multiple selector. As this parameter is optional, the filter is included in the query using an auxiliary parameter (AUX_Product_category). The auxiliary parameter has a default expression that returns " 1 = 1 " when there is no category selected and the corresponding where clause when some categories are selected:

The identifiers can be shown in a Text field with the following Expression:

$P{M_Product_Category_ID}.getString("strIdentifiers")

The BaseReportActionHandler and the ReportingUtils class used to generate the report includes some additional parameters that can be used in the template:

SUBREPORT_DIR

The path where the main template is located. Useful to set the paths of the subreports.

jasper_process

A org.openbravo.client.application.Process object with the Process Definition of the report.

jasper_hbSession

A org.hibernate.Session object with the current hibernate session.

jasper_obContext

A org.openbravo.dal.core.OBContext with the OBContext that has launched the report.

AMOUNTFORMAT

A java.text.DecimalFormat object with the format to be used on Amounts.

QUANTITYFORMAT

A java.text.DecimalFormat object with the format to be used on Quantities.

REPORT_FORMAT_FACTORY

JR Base parameter with the date format.

Current_Client_ID

String with the current AD_Client_ID. Useful to filter the SQL of the report.

Readable_Organizations

Comma separated String with the readable organizations of the User/Role executing the report. Useful to filter the SQL of the report.

Depending on the report output some additional parameters are set:

PDF output:

IS_IGNORE_PAGINATION

with false value to ensure that there report is break in different pages.

XLS output:

IS_IGNORE_PAGINATION

with true value to ensure that there report is not break in different pages and all the results are shown in the same sheet.

In case it is desired to add more parameters that cannot be defined as Parameters of the Process Definition it is possible to use a custom Handler that extends the BaseReportActionHandler and overwrites the addAdditionalParameters method.

It is possible to check all the parameters and values sent to the Jasper Report engine by enabling the DEBUG log level on the org.openbravo.client.application.report.ReportingUtils class by modifying the log4j.lcf file:

Report Datasource Definition

There exists two ways of defining the data to be displayed by the report:

Defining a query in the jrxml template

Providing a datasource to the jrxml template

In case of the second approach, we need to use a custom Handler that extends the BaseReportActionHandler and overwrites the getReportData method. This method receives a parameter map as an argument that contains:

The parameters of the HTTP request

The parameters available inside the Jasper Report. They are available through another map that can be accessed by using the JASPER_REPORT_PARAMETERS key.

Sub-Report Runtime Compilation

In case our process definition report contains sub-reports, the infrastructure allows to compile the sub-reports at runtime. In that case we will need to:

Use a custom Handler that extends the BaseReportActionHandler and overwrites the isCompilingSubreports method. This method will return true.

The parameter name for the sub-report in the main report will follow this pattern: SUBREP_name_of_the_sub_report_file.

The sub-reports (jrxml files) must be placed in the same folder as the main report.

Report Definition

In the Report Definition tab are defined the JR Templates of the report. Each Process Definition can only have a Report definition. It is also needed to define at least one template: HTML, PDF or Excel.