Vaadin Background


Vaadin Background

Vaadin provides a GWT-based server framework so you can reate Rich Apps in Java Without Plugins or JavaScript. Vaadin provides an open data model approach wherein you supply Containers, Properties, and Items that correspond to database Tables, Rows and cells.  The UI controls, such as table, bind to this model interface.

Vaadin also provides add-in components to speed development, including HbnContainer and JPAContainer.  These include providers that automate the Container/Item/Property interface.

You build Vaadin application using only server-side Java, supplying the elements of 
  1. model (data)
  2. 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)
  3. 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.



Vaadin Elements

The key elements are described below.


Interface code

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.


Importantly, the save button requires exception handling:



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 EntityManager named buslogicvaadin

  • 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.




Comments