Geertjan is a DZone Zone Leader and has posted 460 posts at DZone. You can read more from them at their website. View Full User Profile

Vaadin and NetBeans: Enabling Business Applications on the Web

05.02.2014
| 3884 views |
  • submit to reddit
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 {
    @Override
    protected void init(VaadinRequest request) {
        VerticalLayout layout = new VerticalLayout();
        layout.addComponent(new Label("Hello Vaadin!"));
        setContent(layout);
    }
}
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() {
    @Override
    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!

Published at DZone with permission of its author, Geertjan Wielenga.

Comments

Dan Haywood replied on Sat, 2014/05/03 - 4:26am

Good write-up, and nice to see Apache Isis  getting a mention (though of course it works at a higher level of abstraction than the other frameworks that are mentioned).

We did almost use Vaadin for implementing the main Isis viewer, but in the end went with Wicket mostly because I'd already done some work with that framework.  

But we might in the future do a Vaadin-based viewer.  Would love to have your expertise to contribute with that.

Cheers

Dan

Apache Isis PMC Chair

Alejandro Duarte replied on Mon, 2014/05/05 - 10:35am

Hi Dan,

No doubt Apache Isis is in a different level. It would be great to collaborate to implement a Vaadin-based viewer. Actually, given the dynamic nature of the generated user interfaces of Apache Isis applications, I think it is very convenient to use Vaadin.

Please let me know your ideas on this. Maybe you can open a new discussion in a forum or contact me.

Dan Haywood replied on Mon, 2014/05/05 - 12:06pm in response to: Alejandro Duarte

Hi Alejandro,

thanks for replying.

I've sent you a mail via your blog... let's chat offline about this via email.

Cheers

Dan


Hans-Jörg Alles replied on Tue, 2014/05/06 - 1:17am

Hello Alejandro, for the same reasons you told, i picked up the Vaadin framework for our IT-department as the responsible lead software architect in our company. An additional reason for me is the fairly price for the commercial support of the framework and the add-ons. Getting in contact with the vaadin administration and developer since 2011 we first started with the combination NetBeans 6.x / Vaadin 6 and then switched to Eclipse / Vaadin because of the missing visual editor for Vaadin in NetBeans and the future of NetBeans after the bought of Sun by Oracle. Some time later we all find out, that Vaadin is so effectiv, that the teams didn't really need the visual editor and i recognized that the Vaadin people also put some strong focus on NetBeans IDE. I also did some work in the integration of Vaadin portlets into Liferay Portal...really easy together with the features of inter portlet communication. Even complete portal solutions are now based on Vaadin ( see the Magnolia CMS ). So there are no cons to use NetBeans again. Vaadin rocks ! Greatings Hans-Jörg

Alejandro Duarte replied on Wed, 2014/05/07 - 8:22am in response to: Hans-Jörg Alles

Hi Hans-Jörg,

Good to know that commercial support is also a good reason to pick up Vaadin. Regarding the Visual Editor, I would say that it is a good think to have when you are learning the framework. For me it was like a couple of days and I realized that you won't use it frequently once you learn the API. On the other hand, I would say NetBeans should work (and I think they are already doing it) to get the Vaadin Visual Designer for NetBeans given its importance for developers learning the framework.

Regards.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.