Sunday, February 1, 2009

Page 1 of X is weird

First thing I figured out was how silly implementing a "Page 1 of 10" text is in Jasper. It is confusing and quite frankly having a quick function for this would be great.

The issue is that their is no "Number of pages" variable in Jasper. There is a PAGE_NUMBER variable that must be ran twice in two different "evaluation modes".

Jasper has a cool concept of evaluating variables at different times. You can set a variable to evaluate once everytime a report a runs, group changes, every page, etc.

This concept is used to implmenet a "page 1 of 10" text box on your report.

You must seperate your string though which makes formatting a whole lot harder.

What I'd like to do is have a string a text field expression that looks like

"Page: $V{PAGE_NUMBER} of $V{PAGE_COUNT}"

This won't work because the entire expression can only have one type of "evaluation time".

So you have to create a expression with $V{PAGE_NUMBER} with an evaluate time set to "Now" or "Page" to get the current page number, and then another expression with an evalution time of "Report" to get the total page number.

It would be nice if you could do something like

"Page: $V{PAGE_NUMBER}.eval("Now") of $V{PAGE_COUNT}.eval("Report").

Honestly just having a V${TOTAL_PAGE_COUNT} that always evaluated at "Report" would be the clearest.

What would also be cool is "V${PAGE_X_of_Y}" with patterns would save a lot of time.

If I'm wrong about how you go about this please comment.

No comments:

Post a Comment