travega
travega

Reputation: 8415

Print When (last element reached) Expression in JasperReports

Is it possible to generated a "Print When Expression" that detects the last element in an XML datasource file?

Basically I have a report with a column break inserted after a sub-report in a detail band so I can clearly define new pages for the beginning of a new record. But it always leaves me with a blank last page. So I am hoping that I can prevent this if I have a print when condition that prevents the column break if it is the last record element in the XML datasource.

Is this even possible?

Upvotes: 5

Views: 7858

Answers (3)

salipe
salipe

Reputation: 17

You can only change te position type of the objeto to Float, so the Jasper will fit the content em the element above of them ends.

Upvotes: -1

Victor Pinto
Victor Pinto

Reputation: 447

Many years late... if you sure your datasource is a JRBeanCollectionDataSource, you could use:

$V{REPORT_COUNT} == ((net.sf.jasperreports.engine.data.JRBeanCollectionDataSource)ORIGINAL_DATA_SOURCE( )).getData().size()

Upvotes: 0

mdahlman
mdahlman

Reputation: 9390

The problem is that you don't know it's the last element until after you look for the next element. I don't think there is a simple way.

In principle it should be fine to do something like this:
Create a super-report around the entire report. Run the same query in the super-report. Count the rows. Then pass the number of rows to the original report (which is now a subreport) and re-run the query again. Clearly, running the query twice is another drawback.

If the data source were SQL, then I would suggest modifying the SQL to return the number of rows as part of the result set. But for non-SQL data sources, you need some way of knowing the number of rows (well... some way of identifying the last row) before you reach the last row.

Upvotes: 1

Related Questions