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.