Enhanced Navigation in Vaadin with NavigationBuilder

Friday, May 19, 2017

The Idea Behind the Addon

In fact there where multiple reasons why I wanted to create some additional navigation functionality. Chaining calls to build navigation actions seemed just right. With such an approach you can achieve incredibly readable code, when properly formatted.

Besides the readability and the need to create navigation calls in a unified way, I thought that navigation actions often provide good events to trigger your own custom code. An event-handling implementation seemed suitable.

The general purpose was to make it all easier and more accessible. I also wanted to bundle refresh, back and next actions in the implementation, as they are simply navigation calls.

Builder Approach

It seemed fairly logical to apply a builder-pattern in the library. Let’s crack on with a quick example.

NavigationUtils.navigate() .to("") .inNewTab() .withListener(event1 -> LOGGER.trace("Navigating to external url in a new tab.")) .go();

With the above formatting, the chained calls are easy to read. The opening method NavigationUtils.navigate(); provides us with the Builder object from which we’ll always start. In the example above we specify an external destination url and we tell the builder that we’ll want to open the link in a new tab. After that, we attached a listener that executed our own custom code (in this case a simple log output line). Calling .go(); will build our navigation action and perform it right away. Straight forward, right?

In fact, many calls are optional and can simply be left out. The action can also be stored in a variable for later execution. That would look something like the next example.

NavigateExecutor navigation = NavigationUtils.navigate() .to("") .build(); navigation.perform();

This way you can prepare all the required actions beforehand and just perform them whenever needed.

Reduced Boilerplate

At the moment of writing boilerplate code can be slightly reduced. The NavigationUtil class contains a few methods with very common navigation needs pre-configured.

Here are a few examples of how you could use those pre-built actions.

NavigationUtils.createReloadNavigation().withListener(l -> System.out.println("Page reloaded!")).go(); // Adding a listener to the pre-configured navigation.
NavigationUtils.createBackNavigation().go(); // Go back one page in the browser history
NavigationUtils.createNextNavigation().go(); // Go one page forward in the browser history

In fact, that pretty much sums it all up for now. If you have additional ideas for expanding the project, feel free to share them. I will respond to questions and feedback in comments. If you are experiencing issues, please file them on GitHub. They will all be looked at. The addon’s version at the time of writing is 1.1.2. Note that the addon will get updated every so often, so be aware of changes. Interested in other Vaadin stuff? You might as well read my latest Vaadin related article about loading animations.

Author Thibault Helsmoortel works for JUVO as an IT consultant, he describes himself as a Belgian IT enthusiast with a wide range of interests. Enjoys table tennis and meeting friends at the local bar.

View all posts by Thibault Helsmoortel on his blog.


New from the blog

  • Hadoop
    Tuesday, May 2, 2017

    This article covers

    • Why use Hadoop?
    • What is Hadoop?
    • Recognizing Use Cases
    • Some Use Cases


    Apache Hadoop has evolved into the standard platform solution for data storage and analysis.

    Two key aspects of Hadoop have driven its rapid adoption by companies hungry for improved insights into the data they collect:

    • Hadoop can store data of any type and from any source—inexpensively and at very large scale.
    • Hadoop enables the sophisticated analysis of even very large data sets, easily and quickly.
  • Database partitioning
    Tuesday, April 25, 2017

    This blog item describes a mechanism to simulate database table partitioning (in Oracle) without using the Partitioning Option.

  • OLAP and Hadoop
    Tuesday, March 28, 2017

    On-line analytical processing (OLAP) is a category of data processing solutions designed to enable fast queries against raw, structured, multi-dimensional data. OLAP offerings are available from vendors including SAP, Microsoft, IBM, HP and Oracle.

    OLAP solutions are typically used for business intelligence and reporting, business process management, sales management, reporting and forecasting, and financial reporting of high-value, Big Data. OLAP systems are chosen for the ability to analyze multidimensional data in near real-time, support for complex analytical queries, the ability to organize data at query time, and reduced time-to-reporting.