Download User manual
Transcript
iReport User manual
The first method is useful to move a virtual cursor to the next record: in fact we said
that data shown by a JRDataSource are ideally organized in tables. The next method
returns true if the cursor is positioned correctly to the subsequent record, false if
there are no available records.
Every time that JasperReports executes a next, all the fields declared in the report
are filled and all the expressions (starting from those associated with the variables)
are calculated again; subsequently it will be decided if to print the header of a new
group, to go to a new page, etc… When next returns false, the report is ended by
printing all final bands (group footer, column footer, last page footer and the
summary). The next method can be called as many times as there are records
present (or represented) from the datasource instance.
The method getFieldValue is called by JasperReports after a call to next with a true
result. In particular, getFieldValue is executed for every single field declared in the
report (see chapter 7 for the details about how to declare a report field). In the call a
JRField object is passed as a parameter; in it is the name of the field of which you
want to obtain the value, the type of java object that you expect is given back by the
call and the field description (used sometimes to specify information useful at the
datasource to extract the field value).
The type of return value of the getFieldValue method has to be adequate to that
declared in the JRField parameter, except for when a null is returned. The possible
types of return values are: java.lang.Object, java.lang.Boolean, java.lang.Byte,
java.util.Date,
java.sql.Timestamp,
java.sql.Time,
java.lang.Double,
java.lang.Float,
java.lang.Integer,
java.io.InputStream,
java.lang.Long,
java.lang.Short, java.math.BigDecimal, java.lang.String. If java.lang.Object is
requested as a type of return, the method can return an arbitrary type. This is the
case where a datasource is not composed of lots of single typed fields (as so
happens for the records of a database), but by only one field represented from a java
object and used in the expressions through a cast: in the chapter 7 a
it.businesslogic.Person field had been presented as example; it was used with the
syntax:
((it.businesslogic.Person)$F{MyPerson})
because the field type is known to the interpreter of the expressions simply as
Object.
JavaBean set datasource
This datasource allows us to use some JavaBeans as data to fill a report. In this
context a JavaBean is a java class that shows a series of “getter” methods that are
methods like
public <returnType> getXXX()
where <returnType> (the return value) is a generic java class or a primitive type
(such as int, double, etc...).
104