Syntax

Before you start creating reports with DynamicReports, you should consider which java syntax you will use. Java 5 added static imports that allow static methods or constants to be referenced without qualifying them with a class name. DynamicReports provides a lot of static methods of creating every part of a report and therefore you can consider using a static import for these methods. And DynamicReports also provides the abillity to use Method chaining (also known as Fluent interface). Both are useful for code readability, the ability to replace multiple calls to a class with a single one, and for invoking multiple method calls.
Let's see in detail the difference between using and not using a static import and method chaining:

Classic java syntax (without using a static import and method chaining)

JasperReportBuilder report = DynamicReports.report();
report.addColumn(Columns.column("Item", "item", DataTypes.stringType()));
report.addColumn(Columns.column("Quantity", "quantity", DataTypes.integerType()));
report.addTitle(Componens.text("Report title"));
report.setDataSource(dataSource)
report.show();
 

Using a static import for DynamicReports methods and method chaining

import static net.sf.dynamicreports.DynamicReports.*;
report()
   .columns(
     col.column("Item", "item", type.stringType()),  
     col.column("Quantity", "quantity", type.integerType()))  
   .title(cmp.text("Report title"))
   .setDataSource(dataSource)
   .show();
 

As you can see, static imports and method chaining improve readability of the code but they are not mandatory. It's only up to you which code syntax you will prefer to use.
All examples and tutorials in the documentation use static imports and method chaining to provide more readability of the code.
Examples
SimpleReport_ClassicSyntax, SimpleReport_Step01

Latest News

  • Thu
    Jan
    25
    Changes in version 5.1.0 upgrade to JasperReports 6.5.1 removed xhtml and excelapi exporter removed thread safety...
  • Fri
    Jan
    27
    Changes in version 5.0.0 upgrade to JasperReports 6.4.0 upgrade to Java 1.7, DynamicReports is no longer compatibl...
  • Thu
    Jul
    28
    Changes in version 4.1.1 upgrade to JasperReports 6.2.2 added new types of component stretch type minor bug fixes...