You build Vaadin application using only server-side Java, supplying the elements of
- model (data)
- interface (code to create page controls, populate them with model data, and respond to user input to read/update the model, and move to new pages)
- Business Logic (typically services, though replaced here by Automated Business Logic)
This project was created in SpringSourceToolSuite (STS) - a variation of Eclipse - beginning with a standard installation of downloaded
Vaadin. We also utilized the JPAContainer
The key elements are described below.
You then code Java controllers that are responsible for acquiring the data to push into the page, and respond to actions to retrieve new data, update data, and/or move to a new view. We might term this Presentation Business Logic.
The controller is responsible for assuring that updates invoke Transaction Business Logic. It is an anti-pattern to place this logic inside the controller - it should be architected for sharing between controllers and other transaction sources (e.g., message), perhaps in a service.
In a typical database update page, you might expect to find about half of the code as Presentation Business Logic, and half as Transaction Business Logic. In this case, there was nearly 500 lines of Presentation Business Logic. Using traditional approaches
, there would also have been about 500 lines of Transaction Business Logic, though there was none in this case per Automated Business Logic.
Model: JPA Domain Objects
Vaadin is agnostic about how you obtain the model data the controller users to populate the view. In this example, we used Hibernate/JPA:
In the diagram above:
- Interface code invokes
JPAFactory.setup(), which creates a JPA
- This is defined in
persistence.xml (line 3), which configures for Automated Business Logic on line 19
context.xml configures a jdbc dataSource for Tomcat
Transaction Business Logic
As described above, we specified the Transaction Business Logic as shown below, replacing 500 lines of Java code. This is explained in the video on the parent page.