I. Overview
Developers may have a demand for displaying data in a single web report that is connected to multiple databases with the same table structure. How can this be achieved?
II. Principle
Define a class web report extending from an abstract class "com.fr.web.reportlet" and implement the createReport(ReportletRequest arg0) method to return a report object.
Then, set up a new dataset for the returned report object, and add it into the report to modify the template data by putTableData(DSName,tableData) method. In this method, "DSName" refers to the name of the defined dataset (for example, "ds1") and "tableData" is the dataset used.
III. Instructions
1. Define a Class Dataset
The class dataset can be used to acquire values from different databases, or to insert query results from Java into the class dataset and display them in the report. For more details on how to use class dataset, please refer to class data source.
2. Create a New Template
Create a new template "1.cpt", and define a dataset "ds2". Drag and drop the fields in ds2 into the report. Save to the root directory. Please see the configuration below for reference.
Column names of the defined class dataset should be matched with the format of the data table connected via "ds2". In this case, the names ought to be "Name" and "Score", so that granting values to the dataset can bring out corresponding results in the report.
3. Define a Class Web Report
Please see here for detailed codes: https://github.com/finereport-overseas/example/blob/release/10.0/src/main/java/com/fr/demo/NewDateDemo.java
Here we need to call the ArrayTableDataDemo class located in %FR_HOME%\webapps\webroot\WEB-INF\classes\com\fr\data.
4. Compile and Generate a Class File
The Java IDE will carry out the compilation automatically.
Place the compiled NewDateDemo.class into the root directory of the web report. Since the class is in com.fr.demo, you can put it into %FR_HOME%\webapps\webroot\WEB-INF\classes\com\fr\demo.
5. Publish and Preview
Save the file. Startup the report server and go to the following URL to preview the result: http://localhost:8075/webroot/decision/view/report?viewlet=com.fr.demo.NewDateDemo.