Nicolas Frankel is an IT consultant with 10 years experience in Java / JEE environments. He likes his job so much he writes technical articles on his blog and reviews technical books in his spare time. He also tries to find other geeks like him in universities, as a part-time lecturer. Nicolas is a DZone MVB and is not an employee of DZone and has posted 217 posts at DZone. You can read more from them at their website. View Full User Profile

Using GWT widgets in Vaadin 7 - Part 1

  • submit to reddit

Even if Vaadin provides you with plenty of components out-of-the-box, chances are sooner or later, you'll want to use that special GWT widget you just saw the last day. In that case, be happy because Vaadin let you do that. Then, you'll be able to package the component in a simple JAR archive and reuse it in all projects you want, just like Vaadin components themselves. In this 3 parts article series, we'll see how to do just that with Vaadin 7:

  • This first part is about just wrapping GWT widgets in Vaadin components
  • In the second part, we'll see how to configure the client widget from the server component
  • The final part will detail how to communicate from client to server

 The first step it to choose which widget to wrap. As an illustration, we'll use GWT-Bootstrap, a GWT implementation of Twitter Bootstrap and most specifically the com.github.gwtbootstrap.client.ui.Button. Of course, lessons learned here can easily be transposed for other GWT widgets.

Wrapping a GWT widget in Vaadin code requires a couple of classes:

  • The first class to create is the Vaadin component itself. Such components should extends com.vaadin.ui.AbstractComponent (or com.vaadin.ui.AbstractComponentContainer for components that contains other components, which is not the case for buttons):
    public class BootstrapButton extends AbstractComponent {
  • The second class to create is the client widget itself. It's very simple: just extend the wanted GWT widget (the Bootstrap button in our case). Note that it's mandatory to locate it in a ui.client subpackage relative to the above component:
    public class VBootstrapButton extends Button {
        public VBootstrapButton() {
  • The final class will bind the component and the widget. In Vaadin semantics, it's called a connector. Connectors have to extend com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector (or com.vaadin.terminal.gwt.client.ui.AbstractComponentContainerConnector for those widgets that contain other widgets). Connecting is achieved by implement the createWidget() that should return the previously implemented client class and by annotating the connector with the @Connect that takes the server class as the value.
    public class BootstrapButtonConnector extends AbstractComponentConnector {
        protected Widget createWidget() {
            return GWT.create(VBootstrapButton.class);
    It also has to be located in the ui.client subpackage.

GWT reads Java code and renders HTML and JavaScript. When using standard Vaadin components, the code is precompiled and available in the Vaadin JAR, but when adding third-party widgets, we need to compile both Vaadin and the other widgets. In order to achieve this, two things are necessary:

  • First, we have to create a GWT widgetset gwt.xml file, referencing both the Vaadin and the Bootstrap widgetset:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "">
        <inherits name="com.vaadin.terminal.gwt.DefaultWidgetSet" />
        <inherits name="com.github.gwtbootstrap.Bootstrap" />
        <!-- Reduces compilation time in development mode -->
            <set-property name="user.agent" value="safari,gecko1_8" />
  • Then, we have to handle the compilation itself. Either uses the Eclipse Vaadin plugin compilation feature or insert the following snippet in the Maven POM:
                    <extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>

 Sources for this article can be found on GitHub. In the next part, we'll detail how to let developers customize widgets though components on the server side.

Published at DZone with permission of Nicolas Frankel, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Daniel Slazer replied on Tue, 2012/06/12 - 12:04pm

Well without an actual human-readable warning message I can only guess, but one I run into often is that I forget to make a SessionScoped managed bean serializable - that seems to match what is logged here.

Comment viewing options

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