Thursday, November 6, 2014

JasperReport scriptlet example.

JasperReport can manipulate some views in depend from calculated data through report expression mechanism. But report expression has restriction - it must one-string code. So, you can't perform more complex functionality e.g. string manipulation. For such cases JasperReports provides scriptlets. Scriptlets - it java code which executed every time when report request.

 Below I explain how obtain such result:
Picture 1: Obtain data through scriplet.

Tuesday, October 14, 2014

JasperReport and Maven for creating distributive

In previous articles we created some projects with reports which generated with JasperReport. It's time to create distributive and give it to end user. Here I told about running JasperReport reports from java code and used maven to compile and  run it. Here I will use maven for perform next tasks:
  • Clear unnecessary generated  *.jasper files.
  • Create result folder with result jar file, report templates and all necessary dependencies, but exclude extra dependencies such as junit.

Monday, September 29, 2014

Row counting with JasperReport

JasperReport has simple way to count row in report. In this report I will tell about counting records from main and sub-report. I take for base report from "Using JavaBean datasource for report and subreport in iReport" article and add necessary changes for obtain next result:
Picture 1: Line numbering result.

Monday, September 15, 2014

Correct way to wrap text in iReport

Default behaviour of JasperReport with long string is cut by accord to element length. You can change this behaviour by set "Stretch With Overflow" to True.
Picture 1: Set property for wrap long string.

This solution will bring to ugly result: wrapped element will excel among all neighboring elements:

Picture 2: Not suitable wrap.
If such behaviour is not suitable you can fix it in simple way.

Friday, September 12, 2014

Summarize from subreports in JasperReport

One from typically reporting tasks is calculate aggregate operations: summarize, counting, averaging. JasperReport allow run this operation. But if you work with subreports you can meet with strange behavior. Below I will tell about one aggregate operations - calculating sums and pay attention upon not evident moments.

Main principle of summarizing is passing sum value from subreport to main report and accumulate it in accord value on main report. We can modify sample from previous article for get such result:
Picture1: Report with sums.

Monday, September 8, 2014

Runing JasperReport subreport from java code

In previous post I created JasperReport report with subreport and runned it from through iReport. But, I think, more interesting is way to run it from java code.

Wednesday, August 6, 2014

Using JavaBean datasource for report and subreport in iReport

Usually I prefer use pure SQL as datasource for various database-related tasks, e.g. reporting. But for some tasks is better way to use JavaBean as datasource model. Below I will write sample such datasource and reveal how use it for obtain such result.
Picture 1: Report, based on JavaBean datasource.

Tuesday, June 24, 2014

Minus one crutch

I migrated one of my projects used Firebird1.5 to version 2.5. Main problem of this migration was broken backward compability of Firebird SQL-dialect. Because in this project is more than 500 SQL-queries I wrote text analyser for:

  1. get sql from java, python, pascal and self-written DSL.
  2. analyzed sql queries and show recommendation for new version.
So, I migrated FB2.5 month ago and now have some infers:
  • now I haven't problems related with FB1.5 will not work on modern platforms.
  • now don't need external extension (UDF in FB terminology). FB2.5 has own good tools.
  • in FB2.5 have increased performance.
But I have revealed two bad surprises. First surprise: because I can't test queries results I was caught sorting  problems with null values. So, new syntax is more strict. The second problem - on Linux one query works very slow. At the same time on WinXP on VirtualBox this query works in 5 times faster. May be it is only Ubuntu problem, need test on other distros.

Useful link: From Firebird 1.5 to 2.5