InetSoft Reporting Software: Report Bean Example


This report bean example (bean.srt in the examples/docExamples/script directory) is based on the table example. It changes two parts of the report into report beans:

Note: Set your Registry location to examples/docExamples/script. See Registry Configuration in Report Designer for instructions.

  • The report header section is converted into a bean, and the script for calculating the date range is contained in the bean. This allows the bean to be reused across multiple reports without re-implementing the script.
  • The table label and field are changed to a bean. The bean is used to create a total over 1,000 and a total under 1,000.
View the Gallery Register

Figure 3. Report Bean Example

Report Bean Example

Report Header Bean

Making a report bean from the report header does not require any redesign. Simply copy and paste the appropriate elements into a report bean and define the appropriate properties.

  1. Copy and paste the title elements into a report bean.
  2. Select Edit → Bean Definition, add the text property of the subtitle element to the right frame and enter 'subtitle' for the property name.
  3. Add the text property of the section title element to the right frame and enter 'section title' for the property name.

The script on the date field remains the same:

var now = new Date();

switch(now.getMonth()) {
case 0: case 1: case 2:
   text = "1sr Qtr";
   break;
case 3: case 4: case 5:
   text = "2nd Qtr";
   break;
case 6: case 7: case 8:
   text = "3rd Qtr";
   break;
case 9: case 10: case 11:
   text = "4th Qtr";
   break;
}

text = text + ", " + formatDate(now, 'yyyy');

Since the script uses the property of the text element it is attached to, the references are automatically resolved to the current element. To use the bean, simple replace the elements in the report with the bean.

Total Field Bean

The elements for displaying the two totals are almost identical. We will replace these elements with a report bean following a similar procedure:

  1. Copy and paste the total label and textbox fields into a report bean.
  2. Add the label and total field text property to the bean properties on the Bean Property Definition dialog.
  3. Replace the total fields with two 'total field' beans.
  4. Change the table script to assign the calculation results to the bean.
var total1 = 0, total2 = 0;
 
for(var i = 1; i < table.length; i++) {
   var price = table[i]['Total'];

   if(price > 1000) {
      for(var c = 0; c < table[i].length; c++) {
         cellBackground[i][c] = 0xBBFFBB;
      }
      total1 += price;
   }
   else {
      total2 += price;
   }
}
 
totalOver.value = formatNumber(total1, '$#,###.00');
totalBelow.value = formatNumber(total2, '$#,###.00');

A report bean can be a complete component with presentation elements, properties and dynamic behaviors. We will provide additional examples of how to use report beans to encapsulate complete components.