InetSoft Product Instructions: Reusable Report Logic - Report Beans

A report bean is a reusable set of report components that can be managed as a single unit. It is a very effective tool for building component-based reports, improving reusability and reducing report development time.

You can configure report beans (without scripting) to expose certain sets of properties to the report developer, and this approach is sufficient for most reports. However, you can also implement reusable report logic by embedding scripts within beans. The following sections discuss issues related to placing script inside report beans.

Bean Handlers

A report bean is treated as a mini-report. The bean has its own onLoad Handler and onInit Handler, just like a regular report. However, a bean does not have an onPageBreak Handler or onPrint Handler. All page break events are handled by the parent report.

The bean's onInit handler is invoked when the report loads, before the report parameters are prompted. Like the report onInit handler, the bean's onInit handler is invoked exactly once per instance. If a report bean is used in multiple instances in one report, the onInit handler for each instance is executed once.

Script that you attach to a bean runs within bean scope. This means that you can have multiple instances of a bean within the same report, and any script reference to an element within the bean is resolved to the instances inside the self-same bean.

dashboard demo
View a 2-minute demonstration of InetSoft's easy, agile, and robust BI software.

Bean Scripting Scopes

A bean has its own scripting scope, similar to a report's scope, and all elements within the bean fall within the bean's scope. Therefore, if you place a script on an element within a bean, when the script encounters a symbol (variable, property), the server checks for the reference in the following sequence:

1. Search element scope (i.e., properties defined by the element to which the script is attached).

2. Search the bean “report” scope (i.e., properties defined by the onInit Handler and onLoad Handler of the bean containing the element).

3. Search the bean “element” scope (i.e., properties defined by element-level script attached to the bean element within the parent report).

4. Search parent report scope.

5. Search global scope.

Accessing Report Elements of Same Name

Because the server searches bean scope first, variables and elements in the bean will hide objects of the same name in the containing report. To access such objects in the containing report, use the ParentReport Object. For example, if the bean contains a text element with Element ID of 'Title', and the parent report also contains a text element with Element ID of 'Title', you can access the parent report instance as follows:

 parentReport.Title
    or
 parentReport['Title'] 

Dynamically Modifying the Parent Report

Scripts in a bean can dynamically access elements and variables in the parent report scope. For example, you could develop a “toolbar bean” that contains different chart type “buttons”. When the user clicks a button, this changes a chart in the parent report to the selected type. To do this, you could add an onClick Handler script to each button, such as the following:

// script for line chart button 
Graph1.singleStyle['Count(Total)'] = Chart.CHART_LINE 

This bean can then be embedded in any report that has a chart called 'Chart1'. The bean itself contains no chart called 'Chart1'; the server locates the parent report's 'Chart1' at runtime by looking up the name in the scope hierarchy.

Accessing Bean Properties from ParentReport

From within the parent report scope, you can modify the properties of elements located in a bean by using the 'elements' property of the bean.

For example, consider a report that contains a bean called “Bean1,” which in turn contains a text element called “Text1” and a table element called “Table1.” To access the properties of these bean elements from with parent report script, using the following syntax.

Bean1.elements.Text1.text= 'hello'; 
Bean1.elements.Table1.table[0][0] = 'Order ID';
Read why choosing InetSoft's cloud-flexible BI provides advantages over other BI options.