Report UI for Vaadin Framework 8

Hey!

I published a component that allows you to create and render Jasper Reports in plain Java (thanks to DynamicJasper). You can find it here:
https://vaadin.com/directory/component/report-ui

Any feedback is welcome!

Java 8; Vaadin 8.1.7;
add-on version: 1.1;

Hi Alejandro

As I know JasperReports I dedided to try your reportUI add-on but it is not working.
I added the necesary jars in to the proyect’s dependencies and wrote this peace of code:

private void imprimir() {
PrintPreviewReport report = new PrintPreviewReport<>();
report.getReportBuilder()
.setMargins(20, 20, 40, 40)
.setTitle(“Call report”);

VerticalLayout vlReporte = new VerticalLayout();
vlReporte.addComponent(report);
Window wPDF = new Window("", report);
 UI.getCurrent().addWindow(wPDF);

}

When I want to see the PDF I get this type of error:



GRAVE:

java.lang.NoClassDefFoundError
: org/vaadin/reports/PrintPreviewReport at com.lobito.capitannemostock.presentation.forms.FormaListaProductos.imprimir(FormaListaProductos.java:204) at com.lobito.capitannemostock.presentation.forms.FormaListaProductos.lambda$akcijeGumbov$61446b05$3(FormaListaProductos.java:195)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

org.vaadin.reports report-ui 1.1

Is something else I have to do to make this add-on to work?
Thanks,

Aleksander

When do you get this error? Compile time? Runtime?

In Runtime.

How are you compiling the project? How are you running the project? I would need more details in order to help you.

Windows 7 64-bit;
Java 8; Vaadin 8.1.7; add-on version: 1.1;

Hi,

I’m writing a application in netbeans 8.2, deployed on Tomcat 8.
For now on my localhost.

The application is a simple web page created with the Vaadin plug-in.
The “print” button is part of the “CostumComponent” Form besides the other elements.
And the “Window” opens this Form.
.
.
MyForm form = new MyForm();
addWindow(form);
.
.
There were no errors at Maven Dependencies import neither at compiling time.
The tree structure of the jar looks like (attached snapshot), where you can see that “PrintPreviewReport.class” is present.
Maybe the Proyect doesn’t “see it”.

That’s all. Is this enough informations or you need something more?
Thanks.
Aleksander
40104.jpg

[color=#000000]
Hi Alejandro,

Now I managed to run PrintPreviewReport and get the report. Not without errors but still I could see the result. I think that the exception NoClassDefFoundError occurred because I wasn’t built the add-on.
Now I ocasionally get the this exception:
[/color]



WARNING: Cannot serialize sesion attribute com.vaadin.server.VaadinSession.CapitanNemoStockUIServlet for session D5B4960BE3C392E76421EAE6DE8F87A6
java.io.NotSerializableException: ar.com.fdvs.dj.domain.builders.FastReportBuilder
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)

In my applications I’m not dealing with sessions yet. Everything is set by default by Vaadin plug-in.

So, I don’t know what is wrong.

My code looks like this:

[color=#2980b9]
[i]
private void imprimir() {
PrintPreviewReport report = new PrintPreviewReport<>();
report.getReportBuilder()
.setMargins(20, 20, 40, 40)
.setTitle(“Lista de Productos - Prueba”)
.setPrintBackgroundOnOddRows(true)
.addColumn(ColumnBuilder.getNew()
.setColumnProperty(“nombreLargo”, String.class)
.setTitle(“Nombre Largo”)
.setWidth(150)
.build())
.addColumn(ColumnBuilder.getNew()
.setColumnProperty(“nombreCorto”, String.class)
.setTitle(“Nombre Corto”)
.setWidth(100)
.build());

report.setItems(listaProductos);

Window wPDF = new Window(“”, report);
wPDF.setHeight(“500px”);
wPDF.setWidth(“600px”);
UI.getCurrent().addWindow(wPDF);
}
[/i]
[/color]


Also, I would like to know how make this object “report”, let say, “printable PDF browser window” and
it is posible to define the page size of the report, A4, for example?


Aleksander

It seems you have some non-serializable reference in your domain model. You can use the
Window
class and show the report there if that’s what you want. It is possible to use A4, please refer to
DynamicJasper documentation
to learn how.

P.S. When you paste source code here, please use the option to format it (the button that looks like {…}. Otherwise, it’s too hard to read.

Hi i am getting error while updating dependency in pom.xml it is giving error on widgetgetset compile
[ERROR]
An internal compiler exception occurred
[INFO]
com.google.gwt.dev.jjs.InternalCompilerException: Error constructing Java AST
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.translateException(GwtAstBuilder.java:3997)
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.getInternalCompilerException(GwtAstBuilder.java:4404)
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.createMembers(GwtAstBuilder.java:4096)
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.processImpl(GwtAstBuilder.java:3929)
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.process(GwtAstBuilder.java:3971)
[INFO]
at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater$UnitProcessorImpl.process(CompilationStateBuilder.java:129)
[INFO]
at com.google.gwt.dev.javac.JdtCompiler$CompilerImpl.process(JdtCompiler.java:336)
[INFO]
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:470)
[INFO]
at com.google.gwt.dev.javac.JdtCompiler.doCompile(JdtCompiler.java:1040)
[INFO]
at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater.compile(CompilationStateBuilder.java:325)
[INFO]
at com.google.gwt.dev.javac.CompilationStateBuilder.doBuildFrom(CompilationStateBuilder.java:548)
[INFO]
at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:479)
[INFO]
at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:465)
[INFO]
at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:423)
[INFO]
at com.google.gwt.dev.Precompile.precompile(Precompile.java:222)
[INFO]
at com.google.gwt.dev.Precompile.precompile(Precompile.java:202)
[INFO]
at com.google.gwt.dev.Precompile.precompile(Precompile.java:143)
[INFO]
at com.google.gwt.dev.Compiler.compile(Compiler.java:204)
[INFO]
at com.google.gwt.dev.Compiler.compile(Compiler.java:155)
[INFO]
at com.google.gwt.dev.Compiler.compile(Compiler.java:144)
[INFO]
at com.google.gwt.dev.Compiler$1.run(Compiler.java:118)
[INFO]
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:55)
[INFO]
at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:50)
[INFO]
at com.google.gwt.dev.Compiler.main(Compiler.java:125)
[INFO]
Caused by: java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.lookup.MethodBinding.isDefaultMethod()Z
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.createMethod(GwtAstBuilder.java:4191)
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.createMembers(GwtAstBuilder.java:4086)
[INFO]
… 21 more
[INFO]
[ERROR]
at TooltipInfo.java(26): public class TooltipInfo
[INFO]
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration

this error caused by using the pom dependency as mentioned
org.vaadin.reports report-ui 1.1

i am uning vaadin version 8.2.1

Mee too. Error at compile-time of Widgetset:

[INFO]
— vaadin-maven-plugin:8.3.3:compile (default-cli) @ mic-ui —
[INFO]
auto discovered modules [AppWidgetset]

[INFO]
Using com.vaadin:vaadin-client version 8.3.3
[INFO]
Using com.vaadin:vaadin-client-compiler version 8.3.3
[INFO]
Compiling module AppWidgetset
[INFO]
[ERROR]
An internal compiler exception occurred
[INFO]
com.google.gwt.dev.jjs.InternalCompilerException: Error constructing Java AST
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.translateException(GwtAstBuilder.java:3997)
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.getInternalCompilerException(GwtAstBuilder.java:4404)
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.createMembers(GwtAstBuilder.java:4096)
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.processImpl(GwtAstBuilder.java:3929)
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.process(GwtAstBuilder.java:3971)
[INFO]
at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater$UnitProcessorImpl.process(CompilationStateBuilder.java:129)
[INFO]
at com.google.gwt.dev.javac.JdtCompiler$CompilerImpl.process(JdtCompiler.java:336)
[INFO]
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:470)
[INFO]
at com.google.gwt.dev.javac.JdtCompiler.doCompile(JdtCompiler.java:1040)
[INFO]
at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater.compile(CompilationStateBuilder.java:325)
[INFO]
at com.google.gwt.dev.javac.CompilationStateBuilder.doBuildFrom(CompilationStateBuilder.java:548)
[INFO]
at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:479)
[INFO]
at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:465)
[INFO]
at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:423)
[INFO]
at com.google.gwt.dev.Precompile.precompile(Precompile.java:222)
[INFO]
at com.google.gwt.dev.Precompile.precompile(Precompile.java:202)
[INFO]
at com.google.gwt.dev.Precompile.precompile(Precompile.java:143)
[INFO]
at com.google.gwt.dev.Compiler.compile(Compiler.java:204)
[INFO]
at com.google.gwt.dev.Compiler.compile(Compiler.java:155)
[INFO]
at com.google.gwt.dev.Compiler.compile(Compiler.java:144)
[INFO]
at com.google.gwt.dev.Compiler$1.run(Compiler.java:118)
[INFO]
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:55)
[INFO]
at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:50)
[INFO]
at com.google.gwt.dev.Compiler.main(Compiler.java:125)
[INFO]
Caused by: java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.lookup.MethodBinding.isDefaultMethod()Z
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.createMethod(GwtAstBuilder.java:4191)
[INFO]
at com.google.gwt.dev.jjs.impl.GwtAstBuilder.createMembers(GwtAstBuilder.java:4086)
[INFO]
… 21 more
[INFO]
[ERROR]
at DragStartHandler.java(23): public interface DragStartHandler extends EventHandler
[INFO]
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration
[INFO]

[INFO]
BUILD FAILURE
[INFO]

[INFO]
Total time: 13.489 s
[INFO]
Finished at: 2018-04-08T02:24:48+02:00
[INFO]
Final Memory: 35M/360M
[INFO]

[ERROR]
Failed to execute goal com.vaadin:vaadin-maven-plugin:8.3.3:compile (default-cli) on project mic-ui: Command [[
[ERROR]
/bin/sh -c ‘/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/bin/java’ ‘-Xmx1G’ ‘-Dgwt.persistentunitcache=false’ ‘com.google.gwt.dev.Compiler’ ‘-logLevel’ ‘INFO’ ‘-style’ ‘OBF’ ‘-war’ ‘/Users/stefan/Test/mic/ui/target/classes/VAADIN/widgetsets’ ‘-localWorkers’ ‘4’ ‘-failOnError’ ‘-XfragmentCount’ ‘-1’ ‘-sourceLevel’ ‘auto’ ‘-gen’ ‘/Users/stefan/Test/mic/ui/target/.generated’ ‘AppWidgetset’
[ERROR]
]] failed with status 1

Found solution (see https://vaadin.com/forum/thread/16402419/16514051)

Add to maven pom.xml:

<dependency>
   <groupId>org.eclipse.jdt.core.compiler</groupId>
   <artifactId>ecj</artifactId>
   <version>4.6.1</version>
</dependency>

Hello,

Does anyone have the mvn command used for running the TestUI?

Thanks!

Matthew Scott:
Does anyone have the mvn command used for running the TestUI?

mvn jetty:run

Great Addon! Just a friendly query/suggestion.

I have a lot of data that I’m trying to add the jasper report, so it takes a long time to generate a PrintPreviewReport.

I thought it would be good to put the task on a new thread so the UI doesn’t lock. I couldn’t do this with the included PrintPreviewReport because the VaadinSession which attributes were supposed to be set on in buildJasterPrint(List<? extends T> items, DynamicReport report) was always null since it wasn’t on the UI thread:

protected JasperPrint buildJasperPrint(List<? extends T> items, DynamicReport report) throws JRException {
    JasperPrint print = DynamicJasperHelper.generateJasperPrint(report, new ClassicLayoutManager(), items);
    VaadinSession.getCurrent().getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, print);
    return print;
}

I’m not sure if it’s the right approach, but I’ve made a custom version of the PrintPreviewReport, which allows users to pass in a reference the the VaadinSession so that buildJasperPrint(List<? extends T> items, DynamicReport report) and detatch() both work without throwing NPE’s on the VaadinSession.

Now it looks like this:

private VaadinSession session;

public CustomJasperReport(VaadinSession session) {
    this.session = session;
    VerticalLayout mainLayout = new VerticalLayout(htmlLabel);
    mainLayout.setMargin(false);
    setCompositionRoot(mainLayout);
    reportBuilder = buildReportBuilder();
}

public CustomJasperReport(Class<T> type, VaadinSession session, String... columnIds) {
    this(session);
    PropertySet<T> propertySet = BeanPropertySet.get(type);

    for (int i = 0; i < columnIds.length; i++) {
        String columnId = columnIds[i]
;
        PropertyDefinition<T, ?> propertyDefinition = propertySet.getProperties()
                .filter(p -> columnId.equals(p.getName()))
                .findFirst().get();
        addColumn(propertyDefinition);
    }
}

Hi, you can even avoid passing the session and assign it in the constructor:

public CustomJasperReport() {
    this.session = VaadinSession.getCurrent().getSession();
	...
}

Btw, I explain how to implement background report generation in my book: [Data-Centric Applications with Vaadin 8]
(https://www.amazon.com/Data-Centric-Applications-Vaadin-Alejandro-Duarte/dp/1783288841).

Alejandro Duarte:
Hi, you can even avoid passing the session and assign it in the constructor:

public CustomJasperReport() {
    this.session = VaadinSession.getCurrent().getSession();
	...
}

Btw, I explain how to implement background report generation in my book: [Data-Centric Applications with Vaadin 8]
(https://www.amazon.com/Data-Centric-Applications-Vaadin-Alejandro-Duarte/dp/1783288841).

Oh okay, I think i tried that before, but since it’s on a new thread, the Session is always null unless you pass a reference.

Have I done it wrong?

executor.execute(() -> {
    this.reportSimple = new CustomJasperReport<>(session);
    ...
    ...
    ...
}

You can create the component in the original thread and call the setItems method in the new thread.

I have similar problem: I am using spring, hibernate, JPA to get data from database, when I am showing data in a grid, I get more then 10.000 records in a less then 2 sec, but when I try to represent it in a PrintPreviewReport it takes almost 10 sec. Is there anyway to speed it up?

Maybe you can try a profiler and see which part is consuming the time?

When I tried for the first time to get records into Grid I use it this way

Grid<Some> table = new Grid<>(Some.class);

and I noticed that getting grid with records this way was too long. Also I noticed that creating Grid this way was taking much more time then getting records into list from DB. Then I tried this way

Grid<Some> table = new Grid<Some>();

and it was much faster, now I have grid with 10-15.000 records in a less then 2 seconds.So for the report, as I don’t have anything else (just a service getting records into list) and report I am sure that something is wrong with generating report, here is how it looks like…

private PrintPreviewReport<Uplate> buildReport(){
		PrintPreviewReport<Uplate> izvestaj = new PrintPreviewReport<>();
		Style headerStyle = new Style();
		izvestaj.getReportBuilder()
        .setMargins(20, 20, 40, 40)
        .setTitle("Call report")
        .addAutoText("For internal use only", AutoText.POSITION_HEADER, AutoText.ALIGMENT_LEFT, 200, headerStyle)
        .addAutoText(LocalDateTime.now().toString(), AutoText.POSITION_HEADER, AutoText.ALIGNMENT_RIGHT, 200, headerStyle)
        .addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_HEADER, AutoText.ALIGNMENT_RIGHT, 200, 10, headerStyle)
        .setPrintBackgroundOnOddRows(true)
        .addColumn(ColumnBuilder.getNew()
                .setColumnProperty("idUplate", Integer.class)
                .setTitle("запис")
                .build())
        .addColumn(ColumnBuilder.getNew()
                .setColumnProperty("datumVreme", Date.class)
                .setTitle("датум")
                .build())
        .addColumn(ColumnBuilder.getNew()
                .setColumnProperty("brojIzvoda", Integer.class)
                .setTitle("извод")
                .build())
        .addColumn(ColumnBuilder.getNew()
                .setColumnProperty("uplacenIznos", Double.class)
                .setTitle("износ")
                .build());
		
		izvestaj.setItems(uplataService.nadjiSveAktivneUplate());
		izvestaj.setSizeFull();
		return izvestaj;
	}