Sooner or later, while developing a JasperServer–hosted reports, you will require parameteres and input controls which allow you to select more then one value. Usually there is a need for an input control, which allows either single value, single value with an option "ALL", or multiple values. Of course, the input controls are populated from database as I described in previous write-up.

Today I will describe how to create an input control which allows to select multiple values. First of all you need to define a parameter. In iReport's editor panel Document structure right–click on Parameters and select Add… > Parameter. Datatype java.util.Collection is most important setting.

In JasperServer we will define appropriate input control which allows us to select multiple values. Having a source Query in JasperServer defined, we will select Add > Input Control in iReport's JS–Plugin 3.0 panel, select Multi–Select Query type and fill in other values as for Single–Select Query. We will link the input control to the Report Unit.

Last and most important thing is to use the parameter in report. Because there might be various count of parameter values, we will use WHERE table.attr IN(…) clause to restrict the query. Ordinary single–value parameters are encoded using syntax $P{ParameterName}. For multi-value parameters there is a special syntax – $X{IN, table.attr, ParameterName} which generates the query condition. You can use NOTIN insted of IN in case you would like to generate the NOT IN(…) clause.

The multi-select input control will show as a selectbox with multiple lines displayed and you can select multiple values as well.

Comments:

Thank you! that tutorial was very useful!

Posted by Juan on October 27, 2009 at 03:20 PM CET #

Juan, thank, I wrote the tutorial because I was invetigating this solution quite a long time and I could not find any resource on that topic.

Posted by Josef Petrak on October 27, 2009 at 03:44 PM CET #

You can find more on page 67 of the book
[2007] - The Definitive Guide to JasperReports (Expert's Voice) - [Apress] - [1590599276].

Posted by helyair on November 06, 2009 at 05:19 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed

This blog copyright 2009 by Josef Petrak