Java Reference
In-Depth Information
Of course, before we can display the report, we need to generate it by filling
the report template. As we mentioned earlier, when generating reports from a
TableModel , report filling is done by passing the TableModel as a parameter to the
constructor of JRTableModelDataSource , as can be seen in the generateReport()
method in the example.
Normally, when generating reports from a TableModel , report fields must match
the TableModel is column names, as can be seen from the example. Sometimes it is
impractical to use the column names as report fields. JasperReports provides a way
to generate reports from TableModel s without having to map the table columns to
the report fields. We can name our report fields COLUMN_X , where X is the column
index, starting with 0 . The following JRXML template illustrates this. It will generate
a report identical to the one in the previous screenshot.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN"
<jasperReport name="AircraftReportColumnIndex">
<field name="COLUMN_0" class="java.lang.String"/>
<field name="COLUMN_1" class="java.lang.String"/>
<field name="COLUMN_2" class="java.lang.String"/>
<field name="COLUMN_3" class="java.lang.String"/>
<band height="30">
<reportElement x="0" y="0" width="69" height="24"/>
<textElement verticalAlignment="Bottom"/>
<![CDATA[Tail Number: ]]>
<reportElement x="140" y="0" width="69" height="24"/>
<![CDATA[Serial Number: ]]>
<reportElement x="280" y="0" width="69" height="24"/>
<![CDATA[Model: ]]>
Search WWH ::

Custom Search