Over a million developers have joined DZone.

Vaadin and NetBeans: Enabling Business Applications on the Web

DZone 's Guide to

Vaadin and NetBeans: Enabling Business Applications on the Web

· Java Zone ·
Free Resource
Alejandro Duarte is a software developer and the author of Vaadin 7 UI Design by Example.

He currently lives in London, where he works as a consultant for a British IT company.

He maintains two open source products used by several small companies around the world. The first is Enterprise App for Vaadin, a Vaadin add-on to develop CRUD-based applications, while the second is InfoDoc Pro, a simplified workflow software based on Enterprise App for Vaadin.

Alejandro tweets at @alejandro_du and his website is alejandrodu.com.

Aside from and together with Vaadin, one of his favorite tools is NetBeans IDE. After interviewing Bruno Freitas on the Vaadin/NetBeans combination, I interviewed Alejandro to find out why he chose each, and what he thinks of the integration between them.

You're doing a lot of web development and you've been using Vaadin. How did that happen, how did you make that decision?

I came across web development when the web was pretty much static HTML. As a Java developer, and after having a look at the old CGI and popular PHP later, I started to use the Struts framework in my first professional job.

After a while of using Struts, I started to miss the good feeling that you have when coding the presentation layer using Java. I realized that in order for a developer to build web applications, you had to keep getting your fingers dirty with HTML, JavaScript, and probably XML on a daily basis. I really missed the ability to use the IDE´s refactoring tools to change the the presentation layer. Moreover, the world of IT is highly dynamic, developers join and leave teams frequently, which means that being able to flatten the learning curve when a junior developer joins a project is a win. Having to learn not only the underlying web framework but HTML and JavaScript as well, requires an extra effort.

So the search began. After evaluating interesting alternatives such as Apache Isis, Eclipse RCP, Wicket, Ext JS, Groovy and Grails, and even JSF, Flex, and WaveMaker, I found that the easiness and flexibility of Vaadin was the best choice. You can start working on a Vaadin application even if you don't know any Vaadin at all.

Can you briefly describe how Vaadin works, what's unique about it, for anyone who doesn't know about it?

Imagine using Vaadin for the first time. It's as simple as dropping some JAR files inside your "lib" directory and starting to create your UI by coding Java classes. Of course, you can use the Maven archetype or IDEs wizards to create your project too.

Basically, a Vaadin application's starting point is the "init" method of the UI class. You need to override this method by extending the UI. Let me show you an example:

public class MyVaadinUI extends UI {
    protected void init(VaadinRequest request) {
        VerticalLayout layout = new VerticalLayout();
        layout.addComponent(new Label("Hello Vaadin!"));
If you have used Swing, AWT, or any desktop API before, I bet you can easily understand this code. Even if you have not used any desktop API before, chances are that you can understand the code. We are simply creating a layout, adding a label to it, and letting the layout be the content of the page. Here is a screenshot of this simple application:

Similarly, you can add text fields, buttons, combo boxes, tables, trees, and a lot of ready-to use components. You can even extend existing components or create your own components.

Vaadin is based on GWT. With GWT, you can define your UI layer using Java. The GWT Compiler will generate the equivalent JavaScript, HTML, and CSS ready to be rendered in any browser. However, with GWT you will need to code the logic to communicate between client and server. Vaadin adds this part, so you don't need to worry about it. With Vaadin, all UI state is on the server, which leads to simpler architectures for your applications. Look at this piece of code:

Button button = new Button("Click me");
button.addClickListener(new ClickListener() {
    public void buttonClick(Button.ClickEvent event) {
        Notification.show("Thanks for clicking.");
The buttonClick method will run in the server, so communication between client and server is that simple. And could be simpler if you use Java 8 lambdas.

What do you consider to be the top Vaadin features?

I like Vaadin mostly because of three reasons:

  • You can implement your UI layer in Java, meaning that you can take advantage of all the Object Oriented knowledge when you are coding the UI, while truly reusing UI components, something that is difficult when using other web frameworks.
  • Vaadin includes several ready to use, professional-looking themes.
  • Documentation and community is awesome.

What kinds of applications is Vaadin best suited for?

Most of the applications I have worked on are "business applications" for the financial, communication, and education sectors. Some are hosted and accessed inside intranets, while others are deployed to hosting providers and accessed worldwide through the Internet. Most of them have less than a hundred concurrent users at any time. For all these scenarios, Vaadin proved to be an excellent choice.

Usually, the primary concerns when deciding whether or not to go with Vaadin are scalability and flexibility. There is a study showing that Vaadin does scale to an important level. So, I would say that for most projects scalability should not be a limitation when evaluating Vaadin. It's true that Vaadin is mostly a server-side framework. This means that some extra work is done on the server per request. However, most of the requests are AJAX requests that involve changing some part of the client's HTML instead of the whole page. Moreover, you can always use Vaadin Client-Side API to move UI logic to the client side when needed. This last argument can also be used in favor of Vaadin when evaluating flexibility. Vaadin is a mature framework that offers a high degree of flexibility.

In my opinion, the key point when evaluating Vaadin is understanding two important concepts:

  • Vaadin keeps the state of the UI in the HTTP session.

  • A JavaScript client engine containing the logic required to communicate to the server and to get changes is served to the client. This feels like loading an application in the browser and then interacting with the server through this client engine. Of course, you don't have to bother about this when developing Vaadin applications.

So, if you don't have strong reasons not to use the HTTP session (or keep it very very small in size), and if you can accept loading some not very small (not very large though) JavaScript in the first request, Vaadin is a really good candidate for your presentation layer.

And you've been using NetBeans together with Vaadin -- is that a good combination?

Definitely. I think NetBeans was slow prior to 5.5 but now it is a fast IDE with probably the best support for Maven among the IDEs. I prefer to use Maven for Vaadin applications and NetBeans feels like the best choice for this.

And I would add another ingredient to the recipe: Java 8. Lamdas and Method References make writing Vaadin listeners a delight. NetBeans will show hints to convert old listeners to the new lambda notation. Moreover, you can use a wizard to convert all pre-lambda expressions into lambdas for the whole project. NetBeans support for Java 8 is awesome, so NetBeans + Vaadin + Java 8 just rocks!

What are your three favorite NetBeans features for Vaadin developers?

First, the integration with the Vaadin Directory that includes a browser to search Vaadin add-ons inside NetBeans and the ability to use code completion to update the dependencies for Vaadin add-ons as you type. For example, if you start typing ConfirmDialog and press Ctrl+Space, code completion will show the add-on and if you select it, will update your pom.xml to include the dependency.

Second, the project wizards that allows you to create not only Vaadin web applications, but add-ons and TouchKit projects, all of them based on Maven.

And third, the hints and fixes that the editor shows when you are coding custom Vaadin components. For example, NetBeans will show a hint to create a State class when a Connector does not override the getState() method. Very convenient.

Anything else you want to share?

I would say that NetBeans is a really strong option if you are planning to develop Vaadin applications using Maven. Moreover, this is true for other technologies as well. I really like NetBeans support for Java 8, JPA, and JavaFX when compared to other IDEs!

Thanks for taking this interview, Alejandro!


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}