When using this kind of source we can load the data from a resource resolvable through the built-in resource loading mechanism or by means of a backing bean which will offer the data to the source component.
The attributes required to be used with this type of data soruce are reflected in the following table:
Attribute | Optional | Description |
value | false | File, URL or resource which contains the data. |
Valid types for value attribute are:
The most simple usage is based on the built-in resource loading mechanism implemented inside the plugin using following way:
<jr:source type="csv" value="classpath:META-INF/datasource/test.csv" />
First of all, we need to design a JSF Managed Bean which will build the CSV data that will be used by the data source component.
import java.io.*; import javax.annotation.PreDestroy; public class CSVDataBean { private InputStream csvFile; public InputStream getCsvFile() { if (csvFile == null) { // Obtain a csv file from disk csvFile = new FileInputStream( ... ); } return csvFile; } @PreDestroy public void release() { if (csvFile != null) { try { csvFile.close(); } catch(IOException e) { e.printStackTrace(); } } } ... }
Then, this managed bean can be used inside the JSP file that will render the report or report link.
<jr:source type="csv" value="#{CSVDataBean.csvFile}" />