InetSoft Product Information: Accessing Report Elements Programmatically

There are very few reasons to manipulate the visual properties of elements programmatically, as these can be set in the Designer and dynamic behavior can be programmed using the Script features of the Designer. However, there may be cases where we need to bind data to these report elements programmatically. Each report element has a unique ID. The ID is set on the property dialog in the Designer, or returned by the 'add' method for the element. Once the template has been successfully imported to a ReportSheet object, it is possible to access any element using its element ID.

Read Dashboard Reviews
View 2-min Dashboard Demo
InputStream input =
 getClass().getResourceAsStream("/templates/report1.srt");
Builder builder =
 Builder.getBuilder(Builder.TEMPLATE, input);
ReportSheet report = builder.read(".");

ReportElement elem = report.getElement("Text2");
TextElement telem = (TextElement)elem;

Once the element object is obtained, it is possible to access the methods of the element to set its properties and attributes, or write code for complex data processing logic.

Binding Data to a Report Template

If data binding is not specified in a template, the data must be supplied to the report elements at runtime. Associating a data object with an element using the unique element ID performs the runtime data binding. The ID is set in the Designer property dialog and is also returned from the 'add' element function.

The main method for data binding is setElement(). The setElement() method takes an element ID and a value parameter. The element ID must be unique for each element on a report.

Which data types are acceptable for the element depends on the type of element referred to by the element ID. The following element types and data types are supported by the setElement() method:

Table 5. Data Types Associated with an Element

Element Type

Data Types

Section

TableLens, Object[ ][ ]

Table

TableLens, Object[ ][ ]

Form

FormLens, Object[ ][ ]

Text

String, TextLens

TextBox

String, TextLens

Painter

Image, Component, Painter

Subreport

ReportSheet

Example: setElement

An example of using setElement():

ReportSheet report = ...; // load in a template 
// set the contents of 'table1' 
report.setElement("table1", new JTableLens(jTable1)); 
report.print(...);   

If the ID specified in the setElement() method does not exist in the report template, a NoSuchElementException is thrown. If the data type does not match the element type, an IllegalArgumentException is thrown. Since report templates are normally static and would not change from development to deployment, these types of errors are normally very easy to detect.

Since a report template can store all the static data and attributes in a report, it is generally only necessary to call the setElement() method a few times (and often, just once) when setting up a report. This design greatly reduces the programming involved in creating reports and removes the tedious process of laying out report elements by trial and error.

programmatic reporting software vendor

"We actually divide users into three groups. First, we have the front-line users. Those people typically don’t have sophisticated training. They need very simple interfaces, and there should be close to zero training required to get them productive. That’s what is great about interactive dashboards. Simple pointing and clicking allows a great deal of navigation that is very intuitive.

The second type of user is the manager. They typically want a little more sophistication. They want to control their database access a little bit more. For example, they want to be able to change their own dashboards. They want to be able to drill down to the details. But they in no way want to become data analysts.

That’s the third group of people, the business analysts or the power users. Those are the people who specialize in understanding the database, understanding the data, so they can very dynamically generate new information. And this is really the group that we see analyzing away, and really wanting to get into the powerful features beyond the reporting side. These are the people who are actively seeking this kind of analysis that we have been talking about here." - Luke Liang, CEO, InetSoft