开发者

What is jasper report's algorithm for using a data source?

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
     }
     cal开发者_如何学Cl 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜