views:

134

answers:

2

Hi,

I have created my custom data source by implementing the interface JRDataSource. 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 the following: In what way does jasper report call this functions for obtaining the fields in the .jrxml.

E.g:

  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 is just an example, experimentally in fact I found out that it is actually not like that. So my question arised.

Thanks!

A: 

I actually think the algorithm is something like this (simplifying way down and using Java syntax):

while(dataSource.next()) {
   for (JRField field : reportFields)
       currentValues.put(field, dataSource.getFieldValue(field));
}

Fields are declared in the jrxml file independently of where they are displayed.

However, to the best of my knowledge, by default only the detail section is generated (drawn or updated) on a per-record basis. In other words, you'll have to do something fancy if you need to update information in the header or footer of the page.

I believe there is an evaluationTime attribute that can be used in several elements that might be helpful in this regard or you may want to look into the subreport features, depending on how much data you need to work with.

Personally, I've found the JasperReports sample projects to be helpful, though it does require some effort to get much out of them. I'd also point to The Definitive Guide to JasperReports whose name is a lie, but does serve as a decent (and otherwise totally lacking) reference manual.

ig0774
A: 

Can you provide the jrxml for the above code.

Basha