1.Overview
The data source of FineReport can come from not only database or text, but also any other type of data.Since FineReport reads the data source through the abstract class AbstractTableData, and all of the above data sources inherit their abstract methods, users can use a self-defined data source as long as they inherit AbstractTableData. The dataset generated by programming is class dataset.
2.Principles:
AbstrctTableData has 5 main methods to be implemented:
//get count of columns in dataset
public int getColumnCount();
//get the name of the column of index columnIndex
public String getColumnName(int columnIndex);
//decide if the row of index rowIndex exists.It's difficult to iterate all the data to obtain the total number of rows while processing high volume data. It can be readable if it exists
public boolean hasRow(int rowIndex);
//get row count of dataset
public int getRowCount();
//get the value at (rowIndex, columnIndex) in dataset
public Object getValueAt(int rowIndex, int columnIndex);
3.Example
We define a class dataset below with column names to be Name and Score, values to be Alex, 15; Helly, 22; Bobby, 99
3.1 Define Class Data Source
In the beginning, please refer to launch the designer in IDEA[link] and build the environment. Define a class which inherits AbstractTableData and gets the methods implemented. Check out the following link to get more details:
3.2 Compile the Class
Compile ArrayTableDataDemo.java as ArrayTableDataDemo.class
Copy the class file under the path %FR_HOME%\webapps\webroot\WEB-INF\classes .In the end, ArrayTableData.class should be placed under %FR_HOME%\webapps\webroot\WEB-INF\classes\com\fr\data. because the class is in com.fr.data. At this point, class data source has already been defined.
3.3 Configure Class Dataset
Click on Class when choosing data source
Choose ArrayTableDataDemo.class in the poped up window
3.4 Use Class Dataset
The class dataset is good to use after the configuration.It works the same way as other types of dataset. The data can be bound to The cell data columns by drag and drop.
4. Remarks
In the situation of remote design, while using the class dataset, both the server and the local need to equip the class file. Otherwise, the compilation and preview will cause error.