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 206 posts at DZone. You can read more from them at their website. View Full User Profile

Debugging Vaadin Client Widgets

05.27.2012
| 4244 views |
  • submit to reddit

When working with standard Vaadin components, you can rely on your prefered IDE's debugger to help you when something unexpected happens. When integrating add-ons with widgets, chances are that something won't work on the client side sooner or later. In this case, IDE debugging won't help and we need something else.

This something else is GWT hosted mode. The first step to enable this feature is to create a launch in Eclipse. In order to that, right-click on your Eclipse project and choose Properties. In the opening pop-up, select the Vaadin menu (type "Vaadin" in upper left field if you need to reduce the number of menu entries).

Click on the Create development mode launch button: this creates a .launch file at the root of the project. Right click on it and choose Debug as 'GWT hosted mode'. This launches the GWT development mode window. Subsequent runs can be directly started from the Debug configurations tool item.

The second step is to use PRETTY style compilation, either through the previous screen or through Maven, depending on your approach.

The third step is optional but recommended. Since there will be a lot of debugging, updating code and compiling to JavaScript cycles, it will speed them up to compile only for the browser you're currently using. Locate your gwt.xml file and insert the following snippet:

<set-property name="user.agent" value="safari" />

 This will set the user agent to Chrome (as well as you guessed, Safari).

The fourth step consists of installing the corresponding plugin in your browser. Launch the application in an embedded server inside Eclipse. Paste the following URL in your browser http://localhost:8080/custom?gwt.codesvr=127.0.0.1:9997.

Note that Internet Explorer download link doesn't work and that Mozilla Firefox version should be comprised between 3.0 and 10.0 for an available plugin to be found. Either use Google Chrome (or Chromium if you value your privacy). Of course, port and context-root should be customized according to your configuration. Follow the displayed instructions to install the GWT Developer plugin.

From this point on, you get two main assets while debugging:

  • The GWT Development console shows you a bunch of log messages that were previously eaten away. That means you can call GWT.log() in your own code and see the message in the console.
  • You can set breakpoints in Eclipse in client-side code, and expects the execution to stop at these, just like in regular server-side code. With this, you have access to the method calls stack as well as variable values.
There's nothing revolutionary with this technique: GWT developers use it since ages but for Vaadin developers , it's another tool at your disposal to be able to provide top-notch UI components.
Published at DZone with permission of Nicolas Frankel, author and DZone MVB. (source)

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

Comments

Kelis Jameson replied on Sun, 2013/05/12 - 7:53am

divide by two method to quickly identify where the problem occurred and narrow it down to the root code defect.  I like using println() statements for this.

Unfortunately, like others have said, I have often spent time maintaining applications that don't make any sense and weren't developed to be simple and elegant.  The applications were built by a debugger programmer and I need a debugger to follow the execution path just to understand how the crazy thing works and where it is failing in this situation.  Yes, the debugger does imply that the code (or critical section containing the bug) is complex and bad but it still has to be understood enough to fix it.

The debugger can also be useful as a sanity check to verify that a section of code works as you expect, whether as a possible cause of the bug, or whether it correctly reflects your mental model of how new developed logic or a fix actually works.

basketball training tips 

Comment viewing options

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