Integrating Vaadin into Legacy Applications
Join the DZone community and get the full member experience.Join For Free
Though embedding Vaadin parts in legacy applications was covered in Learning Vaadin, you may feel the need to go further toward this goal.
The description I made works, but your user interface has to be neatly separated into different rectangular zones for Vaadin-served iframes or divs to take place. This clearly won't achieve the best integration results: we can do better with the ExternalLayout add-on. It let you compose Vaadin components in your legacy application, irrelevant of where your Vaadin div is located on it: use-cases include a search box, a shopping cart, a menu bar, you name it!
In this article, we'll focus on a menu bar, situated at the top of the page while the main Vaadin application consists of a form located just under the title of a page (see below mockup).
The form creation is easy enough and out of the scope of this article. What we want, however, is to have both the menu bar and the form to be served by the same Vaadin application so as to have possible integration between them.
Here comes the external layout add-on; when embedding a Vaadin application inside a web page, we can put any Vaadin component on any placeholder inside this page, regardless of the position of the embedded application.
Detailed instructions for embedding an application can be found in Learning Vaadin. In order to use the add-on, here are the necessary steps:
- Get the library, either as a download or by using the following Maven dependency:
<dependency> <groupId>org.vaadin.addons</groupId> <artifactId>externallayout</artifactId> <version>1.0</version> </dependency>
- Create the external layout by supplying both the placeholder's id and the desired component:
ExternalLayout elayout = new ExternalLayout("menu", new EclipseMenuBar());
- Finally, add the layout as a component to the window:
That's it! If you provide a simple HTML page with a div which id matches "menu", the menu bar will be rendered on it.
Complete sources for this article can be found on GitHub.
Published at DZone with permission of Nicolas Fränkel, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.