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"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<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"/>
<pageHeader>
<band height="30">
<staticText>
<reportElement x="0" y="0" width="69" height="24"/>
<textElement verticalAlignment="Bottom"/>
<text>
<![CDATA[Tail Number: ]]>
</text>
</staticText>
<staticText>
<reportElement x="140" y="0" width="69" height="24"/>
<text>
<![CDATA[Serial Number: ]]>
</text>
</staticText>
<staticText>
<reportElement x="280" y="0" width="69" height="24"/>
<text>
<![CDATA[Model: ]]>
</text>
</staticText>
<staticText>
 
Search WWH ::




Custom Search