Java Reference
In-Depth Information
<textFieldExpression class="java.lang.String">
<![CDATA[$F{aircraft_serial}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="280" y="0" width="69" height="24"/>
<textFieldExpression class="java.lang.String">
<![CDATA[$F{aircraft_model}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="420" y="0" width="69" height="24"/>
<textFieldExpression class="java.lang.String">
<![CDATA[$F{engine_model}]]>
</textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
The only difference between this JRXML template and the previous one is that we
declared a report parameter in the following line:
<parameter name="hp" class="java.lang.Integer"/>
We then used the declared parameter to dynamically retrieve the horsepower in the
where clause of the report query. As can be seen in the example above, the value
of a report parameter can be retrieved by using the syntax $P{paramName} , where
paramName is the parameter name as defined in its declaration � hp in the example above).
Passing a parameter to a report from Java code is very simple. In most of the
examples we have seen so far, we have been passing an empty HashMap to report
templates when we fill them. The purpose of that HashMap is to pass parameters to
the report template. The following servlet is a new version of the one we saw in the
previous section, modified to send a report parameter to the report template:
package net.ensode.jasperbook;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.Connection;
 
Search WWH ::




Custom Search