Wednesday, February 11, 2009

Use Groovy!!!

Found out that their is a global property of a report called language.

This defaults to Java. You should really change it to groovy which is much easier to use.

http://www.nabble.com/Why-this-error----Cannot-cast-boolean-to-Boolean---td11142994.html

Check out this link which describes using the print when expression. Without groovy you have to do stupid new Boolean(something = something) syntax. The compiler throws a dumb error.

Sunday, February 1, 2009

Doing date formatting in complex expression

From time to time you might want to build a whole string with many variables/fields without having to "butt" two different fields next to each other.

Create a new Text Field and put in an expression like

$F{First_name} + " " + ${Last_name}

Clean and the text will align much better. Now what is one of the fields is a date?

$F{First_field} + " " + (new SimpleDateFormat("MM/dd/yyyy")).format($F{some_date_field})

Java is too the rescue. Jasper expressions can do Java for the most part and this can come in handy. Read the SimpleDateFormat API docs for the full pattern variables available.

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.

Starting a blog

This is a simple blog about my expierences with Jaser. I hope that it will help fill the gap that JasperForge needs to fill. Maybe I'll start working on the project eventually.