Overview

SmartGWT – Common Pitfalls

5 Comments

 

SmartGWT is a very interesting extension to develop rich client web applications. We have used this framework in a project to bring an existing client application to the web.

The countless widgets and the SmartGWT Showcase with its corresponding code snippets were very helpful during implementation phase.

In general we made good experience with the development of this library. However, we noticed a few inconsistencies which we have found workarounds for and I would like to write about here.

Problems of development

IDs of widgets

The IDs of the surface widgets should always be placed directly after the first initialization. If the ID is set after a few assignments as addCellDoubleClickHandler, one will wonder why the double click has no effect.

list = new ListGrid();
list.setID("list");
list.addCellDoubleClickHandler(new SearchResultDoubleClickHandler(this));

This cannot be reproduced with an isolated testcase and the latest SmartGWT 2.4 and GWT 2.2.0. Therefore it seems to be fixed or I used a nightly build.

TextItem.setKeyPressFilter

If you use the function setKeyPressFilter of the TextItem widget problems arise when you also add an own implemented KeyPressHandler. The own KeyPressHandler unfortunately disables the KeyPressFilter. The workaround is to write an additional second KeyPressHandler, which has the same functionality as the framework KeyPressFilter and avoid using of the KeyPressFilter.

private class NumericKeyPressHandler implements KeyPressHandler {
		/**
		 * @see com.smartgwt.client.widgets.form.fields.events.KeyPressHandler#onKeyPress(com.smartgwt.client.widgets.form.fields.events.KeyPressEvent)
		 */
		public void onKeyPress(KeyPressEvent event) {
			if (!event.getKeyName().matches("[0-9]")) {
				event.cancel();
			}
		}
	}

I created a bug report for this issue: http://code.google.com/p/smartgwt/issues/detail?id=576. This bug has been confirmed in SmartGWT version 2.4 and it is fixed in the lately nightly builds.

Problems in the interaction of SmartGWT and automated tests with the Robot Framework

Offline.put/.get

The “Offline” functionality of SmartGWT is a wonderful feature to persist values ​​on the client with HTML5 features and avoid manual setting of cookies. However, we couldn´t find a keyword for our automated robotic tests, which read or write the content of the permanent browser cache. But this can be handled with a simple javascript. This example sets an entry in the “permanent browser cache”.

Execute JavaScript  window.localStorage['${name}']='${value}';

DOCTYPE tag in the HTML Bootstrap file

The SmartGWT best practices prohibit a DocType tag in the bootstrap HTML file to start the Internet Explorer ​​in “quirks mode” for example. However, this leads to no screenshots in automated robotic testing. As solution we created an extra mainAccTest.jsp file for our selenium tests that had a doctype header and the main.jsp included. This jsp is used for the automated testing with automated screenshots enabled.

<%@ page language="java"%>
 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>
 
<!doctype html>
 
<jsp:include page="main.jsp" />

For more SmartGWT expirences have a look at Testing SmartGWT Applications with Selenium and Robot Framework.

Kommentare

  • Charles Kendrick

    Hi Ansgar,

    We can’t reproduce the problem you’re reporting about setID() and event handlers. The follow simple test code works as expected:

            
    ListGrid grid = new ListGrid();
            grid.addCellDoubleClickHandler(new CellDoubleClickHandler() {
                
                @Override
                public void onCellDoubleClick(CellDoubleClickEvent event) {
                    Window.alert("Firing Cell DoubleClick!");
                    
                }
            });
            grid.setID("myGrid");
            
            ListGridField f1 = new ListGridField("f1");
            grid.setFields(f1);
            
            ListGridRecord[] data = new ListGridRecord[] {
                    new ListGridRecord() {{setAttribute("f1", "xxx");}}
            };
            grid.setData(data);
            grid.draw(); 
    

    Let us know if you can find a case where this actually occurs. No other user has ever reported this, so we think it might be an application bug.

    On your other comments, is there something we could do to make Offline functionality more testable? As far as we understand, this same issue would arise with any framework that provides offline support, or even with using localStorage directly.

  • Charles Kendrick

    We’re also unable to reproduce the second issue you’re reporting. Here’s a simple test case that works fine:

            DynamicForm testForm = new DynamicForm();
            TextItem f1 = new TextItem("f1");
            f1.setKeyPressFilter("\\d");
            f1.addKeyPressHandler(new KeyPressHandler() {
                
                @Override
                public void onKeyPress(KeyPressEvent event) {
                    SC.logWarn(event.getKeyName() + " pressed in f1.");
                    
                }
            });
            testForm.setItems(f1);
            
            testForm.draw(); 
    

    If you confirm that neither of these issues are real (or perhaps they applied only to some nightly build you downloaded) it would be great if you could revise your blog post to mention this.

  • Ansgar Schulte

    Ok. I cannot reproduce the Id part. So maybe I used a nightly build. I changed the blog entry for this.
    But I could reproduce the setKeyPressFilter in an isolated testcase and I opened a bug report for it: http://code.google.com/p/smartgwt/issues/detail?id=576

  • Ansgar Schulte

    Ok. I got an comment for my issue: “Fixed post-2.4. Pull latest nightly and retry.”
    So it is fixed in the latest nightly build and it is a defect in the current SmartGWT 2.4 release.

  • Charles Kendrick

    Thanks for following up Ansgar.

    What about this question?

    On your other comments, is there something we could do to make Offline functionality more testable? As far as we understand, this same issue would arise with any framework that provides offline support, or even with using localStorage directly.

Comment

Your email address will not be published. Required fields are marked *