Skip to content

Instantly share code, notes, and snippets.

@vonloxley
Created November 4, 2016 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vonloxley/955b2b25b911906d1260422d842dc34a to your computer and use it in GitHub Desktop.
Save vonloxley/955b2b25b911906d1260422d842dc34a to your computer and use it in GitHub Desktop.
Jump-starting Vaadin with Java EE.

Jump starting Java EE with Vaadin

There is a small but dedicated community around Vaadins integration into the Java EE stack. Relying on the vaadin-cdi and Matti Tahvonen’s cdi-helpers it is possible to literally start a Java EE Application in seconds that

  • has a clean responsive layout
  • a nice menu
  • auto-detects Vaadin views
  • has basic access control.

Getting started

To start with maven, generate a new maven project from the Vaadin-jee7-webapp-archetype:

mvn \
    -DarchetypeGroupId=de.hansche  \
    -DarchetypeArtifactId=vaadin-jee7-webapp-archetype  \
    -DarchetypeVersion=1.0  \
    archetype:generate

and deploy it to your application server.

The generated project has two views that demonstrate how to add your content.

StartView.java is the main view that displays a MarkDown formatted text file (welcome.md) and uses the @ViewMenuItem annotation, ExampleView is the most basic view that can be used.

MainUi.java is the entrance point to the webapp. Please notice, that is quite short and saves a lot of boilerplate code, which is now hidden behind the @CDIUI annotation.

To add a view you simply add a new class that implements View and annotate it with @CDIView("MyViewTitle"). Some magic will find it and generate a menu entry. If you want more control over the menu you can use the ViewMenuItem annotation to add an icon or control the placing of the entry.

Working with entities

If you use Netbeans with the great EntityExpander plugin, it is further possible to generate basic CRUD views with a couple of mouse clicks.

Assuming that you already have an entity (lets call it Person.java) and a corresponding Session Bean, you just have to perform two steps:

  • Right click your entity and choose "Entity Expanders" -> "MaddonForm"
  • Right click your entity and choose "Entity Expanders" -> "TableViewWithPopup"

The first one will generate a Viritin (formerly called "Maddon") AbstractForm, the second a view with a clickable table that shows your data and lets you edit it.

The templates make some assumptions about the names of your class (e.g. PersonFacade.java for your session bean), but any errors should be fixable in no time.

Have fun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment