Hot questions for Using JasperReports in dynamic jasper


Alright, I couldn't find an answer to my question with google so...

Currently I'm using JasperReports and DynamicJasper to build my reports and print them. All works fine when I use just single jasper-files or jrxml-files. I also have a piece of code which merges all JasperPrint-files into one if I need to combine reports. However, this isn't really optimal...

Can I use one .jasper or .jrxml-file as a master report (it has a header, a footer and en empty detail-band) and fill its detail-band with 1-n subreports (currently in .jasper or .jxrml)?

Currently only one of my wannabe subreports use datasource (tablemodel) and other wannabe subreports get their data from parameters.

I've found several different ways to do something which could end up it a result which I want, but so far no success... Which builders/managers/whatever I need? Getting a bit frustrated because can't find enough info about different classes, methods and their parameters. Why they are there and what is required. Examples don't explain enough...

Should I use DynamicReportBuilder to build DynamicReport for the DynamicJasperHelper which generates JasperReport which in turn is filled with JasperFillManager.fillReport method?


Have all sub reports in one main report and use print when expression for visibility. Say following is the subreport code.

   <reportElement uuid="9f36c3cb-7e29-4040-a14e-6a91775e89e4" x="0" y="35" width="555" height="47">
      <printWhenExpression><![CDATA[$P{disp} == 1]]></printWhenExpression>
<!-- Other Element -->

Look out for following line in above code.

<printWhenExpression><![CDATA[$P{disp} == 1]]></printWhenExpression>

This means whole of sub report should be included on when $P{disp}.intValue() == 1. Here $P{disp}, is the parameter you would have to pass to report in order to work with printWhenExpression.

Parameters or not necessary, you can use a field as well. And conditions are based on you requirement.

Note : You can have simillar approach for all subreports.


Using DynamicJasper and FastReportBuilder is it possible to suppress the display of column header(s)?



When FALSE, no column names are printed (in the header band)


FastReportBuilder drb = new FastReportBuilder();

Note: FastReportBuilder inherited method from DynamicReportBuilder since it extends it.


I am using the below code to display the column properties in jasper report. But I am not able to get the three properties values to single column. Is there any possibility to get three of the properties to display using "," in a single column.

The file contains the below code:

DynamicReportBuilder drb = new DynamicReportBuilder();
drb.setTitle("Transaction List Export")
                .setSubtitle("This report was generated at " + new Date())
                .setDetailHeight(15)                    // defines the height for each record of the report
                .setIgnorePagination(true)              // for Excel, we may don't want pagination, just a plain list
                .setMargins(30, 20, 0, 15)              // define the margin space for each side (top, bottom, left and right)
                .setDefaultStyles(titleStyle, subtitleStyle, headerStyle, detailStyle)
                .setColumnsPerPage(1, 10)
                .setUseFullPageWidth(true)              // we tell the report to use the full width of the page. this resizes
                                                        // the columns width proportionally to meat the page width.
                .setReportName("Client List");
AbstractColumn columnClientLocation = ColumnBuilder.getNew()
                .setColumnProperty("ClientAddress", String.class.getName()+Constants.COMMA)
                .setTitle(messages.getMessage(locale, "group.terminalinfo"))
                width = width + 80;

             * We add the columns to the report (through the builder) in the
             * order we want them to appear
            if(myContainer.getServiceProvider().equalsIgnoreCase("GOOG")) {

I am unable to get the values of ClientAddress,ClientCity and ClientPostalCode in a single column of jasper report .

I would like to display all these three properties in a single column.


You can not use "," you need to use CustomExpression to achieve desired result


First add your fields to report, so they can be accessed

drb.addField("ClientAddress", String.class.getName());
drb.addField("ClientCity", String.class.getName());
drb.addField("ClientPostalCode", String.class.getName());

Then create the AbstractColumn with a CustomExpression

AbstractColumn columnClientLocation = ColumnBuilder.getNew().setCustomExpression(
    return new CustomExpression() {
        public Object evaluate(Map fields, Map variables, Map parameters) {
            String clientAddress = (String) fields.get("ClientAddress");
            String clientCity = (String) fields.get("ClientCity");
            String clientPostalCode = (String) fields.get("ClientPostalCode");
            return clientAddress + ", " + clientCity + ", " + clientPostalCode;

        public String getClassName() {
            return String.class.getName();



I fixed it setting the width of Page item, i took all columns width and then set the page size to all columns+100 px , it works fine now


I have created a sample report using the DynamicJasper library. In the report, I need to avoid to print repeated values in a column.

For example, The report has "Dept No" column. Which will be similar for some employees and its in asc order. Which mean it will be only as 1, 2, 3 etc. So, the dept no 1 will be used for some employees and 2 for some employees and so on.

So, here I need to avoid the dept no for an employee in second row, If the employee belongs to first row employee's department.

In the above image, the department no 1 is common for the employee no 101, 102, 103, 104 and 105. So, If dept no is avoid repeated values, then the employee no 102, 103, 104 and 105 would have empty in dept no column and which will be looking like as a group.

How to avoid the repeated values in a column with DynamicJasper?


Without seeing the code, it's difficult to know exactly what to recommend. The ColumnBuilder class has a setPrintRepeatedValues method that can be used similar to the following:


The line of interest that should suppress repeated values is:



Just want to check, does dynamic jasper have any methods for PrintWhenExpression or Conditional style based on a hidden field, my situation is, i am trying to use addConditionalStyles with reference to a value of a hidden field.

For example, fields Name, Telephone Numbers are in the report, i just wanted to highlight all records for which location is 'XXX', where Location is not a visible field in the report, but included in the datasource

example case of conditional style usage


I was able to solve this issue with the following suggestion from Juan Manuel Alvarez Gimenez of FDVSOLUTIONS, thanks Juan

If we need to use fields from the data source that are not directly shown on any column, we must register them like this:

DynamicReportBuilder drb = new DynamicReportBuilder();

drb.addField("location", String.class.getName());

This fields are now available to be used inside custom expressions, or if we use a template which has objects that references this fields



i want to generate jasper report which is used to print on a fixed size stationary. I created html table and place all values in that as per my requirement now i want to print through java so i used jasper report now in that i have columns which is vary on time. As per my requirement i searched on internet and i got dynamic jasper is solution but in that the method add column required column name and pass variable which is from setter getter method but my whole columns are dynamic then how can i generate setter getter method or generate jasper report ?

Look Below Image' border='0' alt="Report" />


Finally i was created pojo of my columns and pass to detail band as a data and then after on bank pojo means which has values are empty spaces for space between columns and data. And then i send my values of columns like this tricky logic i solved my problem


I've got a problem using DynamicJasper 5.0.2 with a Webstart application. In eclipse -> No problem but in webstart I've got this error :

\\storage1\homes\sourin-v\Bureau\ error: package net.sf.jasperreports.engine does not exist
import net.sf.jasperreports.engine.*;

But I'm sure that JasperReport libraries (6.0.4) are in classpath because if I generate a "standard" jasper report in the webstart application it works flawlessly.

Any Ideas ?


My Bad. Missing JDT Compiler in classpath. And it worked with a "standard" jasper report because it was a pre-compiled .jasper report.