What is the jasper report algorithm for using data source?
I created my own datasource by implementing the JRDataSource interface. This interface looks like this:
public interface JRDataSource
{
/**
* Tries to position the cursor on the next element in the data source.
* @return true if there is a next record, false otherwise
* @throws JRException if any error occurs while trying to move
* to the next element
*/
public boolean next() throws JRException;
/**
* Gets the field value for the current position.
* @return an object containing the field value. The object type must
* be the field object type.
*/
public Object getFieldValue(JRField jrField) throws JRException;
}
My question is: how does the jasper report call these functions to get the fields in the .jrxml.
eg:
if( next() )){
call getFieldValue for every field present in the page header
while( next() ){
call getFieldValue for every field present in detail part
}
call getFieldValue for every field present the footer
}
The previous one is just an example, in fact, in fact I found out that in fact it is not. So my question came up.
Thanks!
I actually believe the algorithm is like this (simplifying the way down and using Java syntax):
while(dataSource.next()) {
for (JRField field : reportFields)
currentValues.put(field, dataSource.getFieldValue(field));
}
The fields are declared in the jrxml file regardless of where they appear.
However, as far as I know, by default only the detail section is generated (rendered or updated) based on the record. In other words, you will need to come up with something if you need to update the information in the page header or footer.
I believe there is an attribute evaluationTime
that can be used on multiple elements that might be useful in this regard, or you might want to view the subreport functions depending on how much data you need to work with.
Personally, I've found JasperReports sample projects to be helpful, although it takes some effort to get a lot out of them. I would also point to the Ultimate Guide to JasperReports , whose name is false but does serve as a decent (and otherwise completely missing) guide reference.
a source to share