<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rich Internet Applications (RIA) &#187; GWT</title>
	<atom:link href="http://canoo.com/blog/category/gwt/feed/" rel="self" type="application/rss+xml" />
	<link>http://canoo.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 12 Aug 2010 11:50:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>GWT UiBinder: Better Web App Separation of Concerns</title>
		<link>http://canoo.com/blog/2010/04/26/gwt-uibinder-better-web-app-separation-of-concerns/</link>
		<comments>http://canoo.com/blog/2010/04/26/gwt-uibinder-better-web-app-separation-of-concerns/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 09:44:10 +0000</pubDate>
		<dc:creator>alberto</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>

		<guid isPermaLink="false">http://canoo.com/blog/?p=1057</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2010/04/26/gwt-uibinder-better-web-app-separation-of-concerns/";</script>One of the newest features introduced in Google Web Toolkit 2.0 is the &#8220;UiBinder&#8220;. This new way of building views allows the developer to use a declarative approach when doing the layout of a GWT application. 
In case you have not heard about it, GWT is a set of tools that enables Java developers to [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2010/04/26/gwt-uibinder-better-web-app-separation-of-concerns/";</script><p>One of the newest features introduced in Google Web Toolkit 2.0 is the &#8220;<a href="http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html">UiBinder</a>&#8220;. This new way of building views allows the developer to use a declarative approach when doing the layout of a GWT application. </p>
<p>In case you have not heard about it, GWT is a set of tools that enables Java developers to develop &#8220;rich web applications&#8221; in the Java language. The term &#8220;rich web application&#8221; implies two things:</p>
<ul>
<li>Desktop-like interaction, where a user action has immediate feedback (e.g.: input validation, search box terms suggestions, results highlighting, etc) without requiring a server round-trip (executing an HTTP request with the result of reloading the page being browsed). In the world of web applications, this is typically accomplished using Ajax (what is also what GWT does).</li>
<li>An application running within a browser, but using native browser technologies (HTML, CSS and JavaScript). If we were talking about applications held in browser plug-ins and running out-of-process within their own virtual machines or by mean of run-times, I would prefer to use the more general term &#8220;rich internet applications&#8221;. These are launched from a web browser but behave as black boxes for other user agents (e.g.: web crawlers).</li>
</ul>
<p>GWT allows us is write Ajax-based &#8220;rich web applications&#8221; using the Java language instead of the traditional JavaScript. GWT takes your Java code and compiles into JavaScript, HTML, and CSS. So while you write the program in Java, it is translated into a traditional web application. </p>
<h3>Building user interfaces in GWT</h3>
<p>The most common approach to building desktop application interfaces is using visual components called &#8220;widgets&#8221;. For developers with Swing experience, GWT <em>seems</em> a marvellous step forward because it allows you to leverage most of your knowledge with far less effort than the alternatives. I say seems because this can also be of disadvantage, as I&#8217;ll show with an example.<br />
If we had to create a web interface for a simple web search application, the most common way of doing the interface would be an HTML form for submitting the query and an HTML list to show the results:<br />
<pre><pre style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;">&lt;html&gt;
&lt;head&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Search application&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;searchBox&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Search:&lt;/h2&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;form action=&quot;&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label for=&quot;queryInput&quot;&gt;Query:&lt;/label&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input id=&quot;queryInput&quot; type=&quot;text&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;submit&quot; value=&quot;Go!&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt;
&lt;/div&gt;
&lt;div id=&quot;searchResults&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Results:&lt;/h2&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul id=&quot;results&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;Result 1&lt;/li&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;Result 2&lt;/li&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;Result 3&lt;/li&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ul&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></pre><br />
In the case of GWT, a Swing developer might write widget and layout code like this:<br />
<pre><code style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;">
public class SearchGwt implements EntryPoint {
&nbsp;&nbsp;&nbsp;&nbsp;public void onModuleLoad() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Widget searchBox = createSearchBox(&quot;Query:&quot;, &quot;Go!&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Panel searchResults = createSearchResults();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VerticalPanel mainContainer = new VerticalPanel();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mainContainer.add(new Label(&quot;Search:&quot;));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mainContainer.add(searchBox);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mainContainer.add(new Label(&quot;Results:&quot;));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mainContainer.add(searchResults);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RootPanel.get().add(mainContainer);
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;private Widget createSearchBox(String inputLabel, String buttonLabel) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HorizontalPanel searchBox = new HorizontalPanel();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searchBox.add(new Label(inputLabel));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searchBox.add(new TextBox());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searchBox.add(new Button(buttonLabel));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return searchBox;
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;private Panel createSearchResults() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VerticalPanel searchResults = new VerticalPanel();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 1; i &lt;= 3; i++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searchResults.add(new Label(&quot;Result &quot; + i));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return searchResults;
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</code></pre><br />
This approach is a valid one and, with some CSS styling, produces a neat interface, but it introduces a too complicated DOM structure that does not scale well for bigger applications:<br />
<pre><pre style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;">&lt;html&gt;
&lt;head&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Search GWT application&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;!-- GWT script and iframe tags omitted --&gt;
&lt;div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;gwt-Label&quot;&gt;Search:&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tbody&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td align=&quot;left&quot; style=&quot;vertical-align: top;&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;gwt-Label&quot;&gt;Query:&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td align=&quot;left&quot; style=&quot;vertical-align: top;&quot;&gt;&lt;input type=&quot;text&quot; tabindex=&quot;0&quot; class=&quot;gwt-TextBox&quot;/&gt;&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td align=&quot;left&quot; style=&quot;vertical-align: top;&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;button type=&quot;button&quot; tabindex=&quot;0&quot; class=&quot;gwt-Button&quot;&gt;Go!&lt;/button&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tbody&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/table&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;gwt-Label&quot;&gt;Results:&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;gwt-Label&quot;&gt;Result 1&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;gwt-Label&quot;&gt;Result 2&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;gwt-Label&quot;&gt;Result 3&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></pre><br />
Compare the handcrafted HTML tags with the DOM produced using GWT widgets, and the first one is simpler. One of the reasons of the extra verbosity of the GWT one is the use of &#8220;HorizontalPanel&#8221; to layout the search box horizontally. This is a panel based in tables and it introduces a &#8220;too verbose&#8221; HTML table for the layout. In the case of a horizontal layout, we can also use a FlowPanel, altogether with some CSS styles, to avoid the search box components stacking vertically (which is the default layout for the HTML &#8220;div&#8221; elements that a &#8220;FlowPanel&#8221; produces). The problem is that this approach mixes widgets for layout with CSS for layout (not for styling) what stops being a pure widget approach.<br />
The next thing to notice in the DOM produced by GWT is the excessive presence of GWT CSS classes (e.g.: &#8220;gwt-Label&#8221;, &#8220;gwt-TextBox&#8221;). While they are most times useful when it comes to style the widgets, they are many times not used or they do not fit always our CSS selectors strategy.<br />
Lastly, there is a lack of HTML semantics in the DOM produced by GWT. Almost every element is a &#8220;div&#8221;. From the point of view of web standards, it is much more convenient to use an HTML list for the results as it is to use a collection of &#8220;div&#8221; elements. Producing HTML labels associated with form fields (search box label) is also a usability and accessibility improvement. Using tables for layout should be avoided.<br />
For a real-world application that use input fields, trees, tables, &#8220;tab panels&#8221; or splitters, etc&#8230; all in the same screen, it is a good practice to get rid of the intermediate superfluous DOM elements. It reduces drastically the amount of &#8220;glue&#8221; elements, making the DOM much more compact and faster to modify. We should avoid &#8220;glue&#8221; and automatic generated code, because it needs to be compiled, loaded, executed and maintained. In the case of an overly verbose DOM structure, CSS issues may appear because of the complex structure interactions. Fixing them is akin to fixing bugs in generated code: very difficult!</p>
<h3>Mixing HTML and Widgets</h3>
<p>So how can we mix widgets and html properly? Before GWT version 2.0, the most common way was to use &#8220;RootPanel.get(&#8217;someId&#8217;)&#8221; to access an HTML element in the application host page, and then create an object there to attach the widgets to (ie. a &#8220;RootPanel&#8221;). If we need to embed only a few widgets in the host page, this technique suffices. But doing this in a real application with a large number of widgets becomes complex and slow.<br />
UiBinder scales better because it does not inject widgets into the HTML of the host page. Instead, you declare your layout in a stand-alone HTML file that can be composed with other components as many times as necessary to build more complex interfaces. Composition entails componentization, allowing the developer to create subparts of the user interface (UI components) that can be packaged, re-used and tested in isolation.<br />
But let us see how with an example:<br />
<pre><code style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;">
public class SearchGwt implements EntryPoint {
&nbsp;&nbsp;&nbsp;&nbsp;public void onModuleLoad() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SearchComponent searchComponent = new SearchComponent();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RootPanel.get().add(searchComponent);
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</code></pre><br />
<pre><pre style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;">&lt;ui:UiBinder xmlns:ui=&#039;urn:ui:com.google.gwt.uibinder&#039;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:g=&#039;urn:import:com.google.gwt.user.client.ui&#039;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;g:HTMLPanel&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;searchBox&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Search:&lt;/h2&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;form action=&quot;&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label for=&quot;queryInput&quot;&gt;Query:&lt;/label&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input id=&quot;queryInput&quot; type=&quot;text&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;submit&quot; value=&quot;Go!&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;searchResults&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Results:&lt;/h2&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul id=&quot;results&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;Result 1&lt;/li&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;Result 2&lt;/li&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;Result 3&lt;/li&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ul&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/g:HTMLPanel&gt;
&lt;/ui:UiBinder&gt;</pre></pre><br />
<pre><code style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;">
public class SearchComponent extends Composite {
&nbsp;&nbsp;&nbsp;&nbsp;interface Binder extends UiBinder&lt;Widget, SearchComponent&gt; {
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;private static Binder uiBinder = GWT.create(Binder.class);

&nbsp;&nbsp;&nbsp;&nbsp;public SearchComponent() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;initWidget(uiBinder.createAndBindUi(this));
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</code></pre><br />
Our example has been split into three files: the first one is the GWT entry point, that now only instantiates and inserts our new UI component at the interface top level. The second is an XML file representing the view and is required by UiBinder to act as a mark-up template. The third is the Java class implementing the component logic (that as of now is almost non-existent) and invoking UiBinder.<br />
If you run this code so far, you will notice that now the appearance is exactly the same as in the handcrafted HTML and that there is not yet real integration between the view of the component (mark-up template) and the logic of the component (Java class). Let us fix this by substituting the HTML input field with a GWT &#8220;TextBox&#8221;:<br />
<pre><pre style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;">&lt;ui:UiBinder xmlns:ui=&#039;urn:ui:com.google.gwt.uibinder&#039;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:g=&#039;urn:import:com.google.gwt.user.client.ui&#039;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;g:HTMLPanel&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;searchBox&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Search:&lt;/h2&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;form action=&quot;&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label for=&quot;queryInput&quot;&gt;Query:&lt;/label&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;g:TextBox ui:field=&quot;queryInput&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;submit&quot; value=&quot;Go!&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;searchResults&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Results:&lt;/h2&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul id=&quot;results&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;Result 1&lt;/li&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;li&gt;Result 2&lt;/li&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;li&gt;Result 3&lt;/li&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ul&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/g:HTMLPanel&gt;
&lt;/ui:UiBinder&gt;</pre></pre><br />
<pre><code style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;">
public class SearchComponent extends Composite {
&nbsp;&nbsp;&nbsp;&nbsp;interface Binder extends UiBinder&lt;Widget, SearchComponent&gt; {
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;private static Binder uiBinder = GWT.create(Binder.class);

&nbsp;&nbsp;&nbsp;&nbsp;@UiField
&nbsp;&nbsp;&nbsp;&nbsp;TextBox queryInput;

&nbsp;&nbsp;&nbsp;&nbsp;public SearchComponent() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;initWidget(uiBinder.createAndBindUi(this));
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</code></pre><br />
Notice the changes in the template where the HTML input field has been substituted by &#8220;<g:TextBox...>&#8221; and also the little change in the Java class that now has a field of type &#8220;TextBox&#8221; annotated with &#8220;UiField&#8221;. When the Java class is instantiated, the UiBinder creates and injects the &#8220;TextBox&#8221; using the matching field name and &#8220;ui:field&#8221; attribute. The result is almost the same DOM structure with only some extra attribute values generated by GWT. Note that we also eliminated the &#8220;id&#8221; HTML attribute. This last change is because of a current limitation in UiBinder which does not allow defining both attributes in the same element. This issue can be solved setting the id attribute in the constructor after the UiBinder has been invoked.<br />
As next step, let us now integrate the results list by writing out some simple HTML list elements:<br />
<pre><pre style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;">&lt;ui:UiBinder xmlns:ui=&#039;urn:ui:com.google.gwt.uibinder&#039;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlns:g=&#039;urn:import:com.google.gwt.user.client.ui&#039;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;g:HTMLPanel&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;searchBox&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Search:&lt;/h2&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;form action=&quot;&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label for=&quot;queryInput&quot;&gt;Query:&lt;/label&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;g:TextBox ui:field=&quot;queryInput&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;submit&quot; value=&quot;Go!&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;searchResults&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Results:&lt;/h2&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul ui:field=&quot;results&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/g:HTMLPanel&gt;
&lt;/ui:UiBinder&gt;</pre></pre><br />
<pre><code style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;">
public class SearchComponent extends Composite {
&nbsp;&nbsp;&nbsp;&nbsp;interface Binder extends UiBinder&lt;Widget, SearchComponent&gt; {
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;private static Binder uiBinder = GWT.create(Binder.class);

&nbsp;&nbsp;&nbsp;&nbsp;@UiField
&nbsp;&nbsp;&nbsp;&nbsp;TextBox queryInput;
&nbsp;&nbsp;&nbsp;&nbsp;@UiField
&nbsp;&nbsp;&nbsp;&nbsp;UListElement results;

&nbsp;&nbsp;&nbsp;&nbsp;public SearchComponent() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;initWidget(uiBinder.createAndBindUi(this));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;queryInput.getElement().setId(&quot;queryInput&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 1; i &lt;= 3; i++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results.appendChild(createResultsItem(&quot;Result &quot; + i));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;private Element createResultsItem(String value) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LIElement result = Document.get().createLIElement();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result.setInnerHTML(value);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return result;
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</code></pre><br />
The changes in the UI Binder template is almost the same as the previous one with a subtle difference: in the previous step, we integrated a GWT widget (&#8221;TextBox&#8221;) replacing the HTML input element. In this second case, we performed a to &#8220;bind&#8221; the &#8220;ul&#8221; HTML element from the view because there is no GWT list widget that matches a simple HTML list. Instead of using the API of a GWT widget, we are using the GWT DOM API to directly modify it.</p>
<h3>Adding behaviour</h3>
<p>Let us now go back to the first GWT approach and modify it to create the results when clicking the button. This is what your pre-UiBinder code might look like:<br />
<pre><code style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;">
public class SearchGwt implements EntryPoint {
&nbsp;&nbsp;&nbsp;&nbsp;public void onModuleLoad() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Panel searchResults = new FlowPanel();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Widget searchBox = createSearchBox(&quot;Query:&quot;, &quot;Go!&quot;, searchResults);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FlowPanel mainContainer = new FlowPanel();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mainContainer.add(new Label(&quot;Search:&quot;));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mainContainer.add(searchBox);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mainContainer.add(new Label(&quot;Results:&quot;));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mainContainer.add(searchResults);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RootPanel.get().add(mainContainer);
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;private Widget createSearchBox(String inputLabel, String buttonLabel,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Panel searchResults) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HorizontalPanel searchBox = new HorizontalPanel();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searchBox.add(new Label(inputLabel));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searchBox.add(new TextBox());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searchBox.add(new Button(buttonLabel,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;createClickHandler(searchResults)));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return searchBox;
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;private ClickHandler createClickHandler(final Panel searchResults) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return new ClickHandler() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public void onClick(ClickEvent event) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 1; i &lt;= 3; i++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searchResults.add(new Label(&quot;Result &quot; + i));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</code></pre><br />
Here we introduced a &#8220;ClickHandler&#8221; that modifies the results container with some fake ones when the search button is clicked.<br />
Doing the same with the UiBinder approach results on the following code:<br />
<pre><pre style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;">&lt;ui:UiBinder xmlns:ui=&#039;urn:ui:com.google.gwt.uibinder&#039;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xmlns:g=&#039;urn:import:com.google.gwt.user.client.ui&#039;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;g:HTMLPanel&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;searchBox&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Search:&lt;/h2&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label for=&quot;queryInput&quot;&gt;Query:&lt;/label&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;g:TextBox ui:field=&quot;queryInput&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;g:Button ui:field=&quot;searchButton&quot; text=&quot;Go!&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;searchResults&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Results:&lt;/h2&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul ui:field=&quot;results&quot;/&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/g:HTMLPanel&gt;
&lt;/ui:UiBinder&gt;</pre></pre><br />
<pre><code style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;">
public class SearchComponent extends Composite {
&nbsp;&nbsp;&nbsp;&nbsp;interface Binder extends UiBinder&lt;Widget, SearchComponent&gt; {
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;private static Binder uiBinder = GWT.create(Binder.class);

&nbsp;&nbsp;&nbsp;&nbsp;@UiField
&nbsp;&nbsp;&nbsp;&nbsp;TextBox queryInput;
&nbsp;&nbsp;&nbsp;&nbsp;@UiField
&nbsp;&nbsp;&nbsp;&nbsp;Button searchButton;
&nbsp;&nbsp;&nbsp;&nbsp;@UiField
&nbsp;&nbsp;&nbsp;&nbsp;UListElement results;

&nbsp;&nbsp;&nbsp;&nbsp;public SearchComponent() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;initWidget(uiBinder.createAndBindUi(this));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;queryInput.getElement().setId(&quot;queryInput&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;@UiHandler(&quot;searchButton&quot;)
&nbsp;&nbsp;&nbsp;&nbsp;void buttonClick(ClickEvent event) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 1; i &lt;= 3; i++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results.appendChild(createResultsItem(&quot;Result &quot; + i));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;private Element createResultsItem(String value) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LIElement result = Document.get().createLIElement();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result.setInnerHTML(value);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return result;
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</code></pre><br />
We introduced a &#8220;Button&#8221; GWT widget in the mark-up template together with its corresponding field in the Java class. We also moved the code creating the results to its own method annotated with &#8220;UiHandler&#8221; (take into account that the signature must be compatible with a &#8220;ClickHandler&#8221;). Finally, we removed the &#8220;form&#8221; element from the mark-up (which is not required at all in an Ajax application).<br />
One of the core design principles in the development world is the benefits of separating logic and presentation. What would happen if now we wanted to change the place where the results appear in relation to the search box? Or, if we wanted to get rid of the &#8220;Results:&#8221; label because it is not necessary? In the first GWT approach taken, the way in which the widgets are created and nested is reflected in the Java code together with our logic, making necessary changes to this code. Also &#8220;static&#8221; presentational elements, like the &#8220;Results:&#8221; label, are embedded in the code where. Applying the separation of concerns principle tells us that they do not belong there. Making a change to either presentation or logic necessarily requires changing <em>both</em> presentation and logic. In the &#8220;UiBinder&#8221; approach, because of its inherent separation of concerns, these changes would happen only in the mark-up template or in the domain logic, not in both.</p>
<h3>Conclusions</h3>
<ul>
<li>When building a web application, no matter which framework you use, never forget that you are still using HTML, CSS and JavaScript. The simpler the DOM produced, the faster the application will perform and the less CSS issues you will find.</li>
<li>Web applications have web pages! Always try to use the most semantic HTML structure you can. It improves SEO, usability and accessibility and usually produces compact DOM structures.</li>
<li>Even when you program in your favourite language and do everything in code by mean of widgets, do not forget the advantages of principles like presentation and logic separation. Using UiBinder in GWT produces twice the number of files but each is simpler, cleaner, easy to manage, and easier to maintain.</li>
<li>With presentation separation, you can let your design team produce a HTML prototype of the different parts of your application that can be easily reused afterwards or even in parallel. Two teams being able to work in parallel reduces the project time span and using prototypes reduces the project risks.</li>
<li>Because different tasks require different skills, let the developers code and the designers deal with HTML and CSS. They all will be much happier and the application will be and look much better.</li>
</ul>
<script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><div style="float: left; width: 140px; height: 21px; overflow: hidden; position: relative; left: 8px;"><script>//<![CDATA[
reddit_url="http://canoo.com/blog/2010/04/26/gwt-uibinder-better-web-app-separation-of-concerns/";
//]]&gt;
</script><script language="javascript" src="http://reddit.com/button.js?t=1"></script></div>]]></content:encoded>
			<wfw:commentRss>http://canoo.com/blog/2010/04/26/gwt-uibinder-better-web-app-separation-of-concerns/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Jazoon &#8216;09: RIA and Security</title>
		<link>http://canoo.com/blog/2009/06/23/jazoon-09-ria-and-security/</link>
		<comments>http://canoo.com/blog/2009/06/23/jazoon-09-ria-and-security/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 13:54:50 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java RIA]]></category>
		<category><![CDATA[Jazoon]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>

		<guid isPermaLink="false">http://canoo.com/blog/?p=451</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2009/06/23/jazoon-09-ria-and-security/";</script>Session title: RIA Security: Broken by Design
From: Joonas Lehtinen, CEO IT Mill
IT Mill is the creator of Vaadin: A 100% Java tool for RIA.
Joonas outlines a spectrum of complexity from Basic site to 3D games examples:
Web Sites (Wikipedia), AJAX Sugar (Facebook), Full RIA
He divides „Full RIA“ divide into client side vs. Server driven. Gives a [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2009/06/23/jazoon-09-ria-and-security/";</script><p>Session title: RIA Security: Broken by Design<br />
From: Joonas Lehtinen, CEO IT Mill</p>
<p>IT Mill is the creator of Vaadin: A 100% Java tool for RIA.</p>
<p>Joonas outlines a spectrum of complexity from Basic site to 3D games examples:<br />
Web Sites (Wikipedia), AJAX Sugar (Facebook), Full RIA</p>
<p>He divides „Full RIA“ divide into client side vs. Server driven. Gives a crash course in GWT.</p>
<p>Vaadin: Apparently 100% Java and server driven, which sounds an awful lot like ULC at this stage&#8230; But here’s a difference: It builds on GWT and relies on JavaScript on the client-side.</p>
<p>He goes on to present a bunch of development rules:</p>
<p>Rule #1: Don&#8217;t trust the browser<br />
Rule #2: Complexity is a hiding place for bugs<br />
Rule #3: Large surface give more opportunities for attack. This surface has increased with Web 2.0.</p>
<p> </p>
<p style="text-align: center;"><a href="http://canoo.com/blog/wp-content/uploads/2009/06/p1010092.jpg"><img class="alignnone size-medium wp-image-453" title="p1010092" src="http://canoo.com/blog/wp-content/uploads/2009/06/p1010092-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p> </p>
<p>Difference between GWT and Vaadin architectures is that GWT relies on the client invoking a server-side Web Service API, whereas Vaadin renders the client&#8217;s view on the server.</p>
<p>Erm&#8230; he then offers the cures for the problems (Rules above)&#8230; which I miss because the explanation is compressed into around 5s.</p>
<p>I&#8217;m starting to dislike this presentation at this point. Because here comes another artificial security issue scenario&#8230; which <em>guess which product</em> solves. And I thought product placement in Hollywood movies was irritating.</p>
<p>The issues he raises are legitimate, but the lack of objectivity is obscuring the message. And as I write the presenter is debugging JavaScript which depends on analysing the DOM on the client side &#8211; I&#8217;m not sure if he&#8217;s now analysing the problem or trying to fix it!?</p>
<p>I am formally declaring myself lost at this stage. At least I hope the other attendees are getting something out of this presentation, which has lost focus IMO.</p>
<p>He continues with a discussion about attacking at the transport level, inserting new data on the fly. But come on: A secure transaction in this technical setting will operate under HTTPS, which in most instances will deal with this kind of attack. Unless, of course, that&#8217;s something else I missed.</p>
<p>I think I need a coffee!!!</p>
<script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><div style="float: left; width: 140px; height: 21px; overflow: hidden; position: relative; left: 8px;"><script>//<![CDATA[
reddit_url="http://canoo.com/blog/2009/06/23/jazoon-09-ria-and-security/";
//]]&gt;
</script><script language="javascript" src="http://reddit.com/button.js?t=1"></script></div>]]></content:encoded>
			<wfw:commentRss>http://canoo.com/blog/2009/06/23/jazoon-09-ria-and-security/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Computerworld.ch on GWT and UltraLightClient</title>
		<link>http://canoo.com/blog/2008/08/04/computerworldch-on-gwt-and-ultralightclient/</link>
		<comments>http://canoo.com/blog/2008/08/04/computerworldch-on-gwt-and-ultralightclient/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 09:37:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[UltraLightClient]]></category>
		<category><![CDATA[comparing GWT and Canoo ULC]]></category>
		<category><![CDATA[computerworld.ch]]></category>
		<category><![CDATA[feature article]]></category>
		<category><![CDATA[Stefan Thomas]]></category>

		<guid isPermaLink="false">http://canoo.com/blog/?p=277</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2008/08/04/computerworldch-on-gwt-and-ultralightclient/";</script>Here is a link to an older Computerworld.ch article comparing Google Web Toolkit and Canoo&#8217;s Java RIA library, UltraLightClient (in German only).

Google Web Toolkit und Ultra Light Client
Die Anbindung an das Internet und ein Browser gehören heute zur Standardausrüstung eines jeden Arbeitsplatzrechners oder Heim-PCs.
Stefan Thomas
Viele neue Anwendungen werden darum als HTML-basierte Web-Anwendungen implementiert, die leicht [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2008/08/04/computerworldch-on-gwt-and-ultralightclient/";</script><p>Here is a link to an <a href="http://www.computerworld.ch/aktuell/developerworld/43649/index1.html">older Computerworld.ch article</a> comparing <a href="http://code.google.com/webtoolkit/overview.html">Google Web Toolkit</a> and Canoo&#8217;s Java RIA library, <a href="http://www.canoo.com/ulc/">UltraLightClient</a> (<em>in German only</em>).</p>
<p><a href="http://www.computerworld.ch/aktuell/developerworld/43649/index1.html"><img src="http://canoo.com/blog/wp-content/uploads/2008/08/computerworldch-300x44.jpg" alt="Computerworld online" title="computerworldch" width="200"  /></a></p>
<blockquote><p>Google Web Toolkit und Ultra Light Client</p>
<p>Die Anbindung an das Internet und ein Browser gehören heute zur Standardausrüstung eines jeden Arbeitsplatzrechners oder Heim-PCs.</p>
<p>Stefan Thomas</p>
<p>Viele neue Anwendungen werden darum als HTML-basierte Web-Anwendungen implementiert, die leicht verteilt und aktualisiert werden können und von überall, zu jeder Zeit genutzt werden können. Durch den Einsatz von AJAX-Technologien konnte die Benutzerfreundlichkeit der Oberflächen in den letzten Jahren deutlich gesteigert werden, allerdings bei gleichzeitig wachsender Komplexität in der Anwendungsentwicklung. Bibliotheken, Toolkits und Frameworks versprechen hier eine Erleichterung. Beispielsweise durch die Abstraktion der unterschiedlichen JavaScript-Implementierungen der Browser oder durch vorgefertigte, komplexere Bedienelemente wie Menübalken, Tabreiter oder Baumstrukturen.
</p></blockquote>
<p>The article was written by UltraLightClient customer <a href="http://idaplan.com/en/index.html">Dr. Stefan Thomas</a>. Dr. Thomas is an independent consultant, that has developed two large corporate web applications with <a href="http://www.canoo.com/ulc/ ">Canoo&#8217;s UltraLightClient</a> for a global retailer.</p>
<p><strong>GWT vs. ULC:</strong></p>
<p>Comparing the two is a bit like comparing apples and pears (<a href="http://www.computerworld.ch/aktuell/developerworld/43649/index1.html">the article</a> discusses this). On the other hand, the two widget libraries can be used for similar web applications. And both of them address Java developers. </p>
<p>See also the corresponding product websites:<br />
<a href="http://code.google.com/webtoolkit/">Google Web Toolkit</a><br />
<a href="http://www.canoo.com/ulc/">Canoo UltraLightClient</a></p>
<script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><div style="float: left; width: 140px; height: 21px; overflow: hidden; position: relative; left: 8px;"><script>//<![CDATA[
reddit_url="http://canoo.com/blog/2008/08/04/computerworldch-on-gwt-and-ultralightclient/";
//]]&gt;
</script><script language="javascript" src="http://reddit.com/button.js?t=1"></script></div>]]></content:encoded>
			<wfw:commentRss>http://canoo.com/blog/2008/08/04/computerworldch-on-gwt-and-ultralightclient/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jazoon 08 Day I</title>
		<link>http://canoo.com/blog/2008/06/25/jazoon-08-day-i/</link>
		<comments>http://canoo.com/blog/2008/06/25/jazoon-08-day-i/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 10:04:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[Google Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Jazoon]]></category>
		<category><![CDATA[brief overview]]></category>
		<category><![CDATA[day 1]]></category>
		<category><![CDATA[jazoon 08]]></category>
		<category><![CDATA[sihlcity]]></category>
		<category><![CDATA[zurich]]></category>

		<guid isPermaLink="false">http://canoo.com/blog/?p=269</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2008/06/25/jazoon-08-day-i/";</script>
Here are some quick notes on the sessions I attended yesterday at Sihlcity. I believe Jazoon will be uploading videos and slides very soon:
First in my lineup was a talk on using Google Web Toolkit for a business application in a typical enterprise environment. This was kind of like a case study. Dmitry Buzdin talked [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2008/06/25/jazoon-08-day-i/";</script><p><a href="http://www.flickr.com/photos/canoo/2609288583/" title="jazoon by canoo engineering, on Flickr"><img src="http://farm4.static.flickr.com/3078/2609288583_756f72145e_m.jpg" width="240" height="180" alt="jazoon" /></a></p>
<p>Here are some quick notes on the sessions I attended yesterday at Sihlcity. I believe Jazoon will be uploading videos and slides very soon:</p>
<p>First in my lineup was a talk on using Google Web Toolkit for a business application in a typical enterprise environment. This was kind of like a case study. Dmitry Buzdin talked about the experience his company gained and listed the various pros and cons.</p>
<p>Next, I listened in to Bruno Schäffer&#8217;s talk together with Christoph Henrici and Daniel Buffet of APG. The talk described the migration of an Oracle Forms application to Java forms for the advertising industry. Main requirement: development and application performance had to remain just as fast as with Oracle Forms. A requirement that the migrated application managed to over-fulfill. </p>
<p><a href="http://www.flickr.com/photos/canoo/2610175088/" title="IMG_5023 by canoo engineering, on Flickr"><img src="http://farm4.static.flickr.com/3208/2610175088_2fba5ea635_m.jpg" width="180" height="240" alt="IMG_5023" /></a></p>
<p>Canoo&#8217;s Andreas Hölzl and Christian Stettler presented their Google Android experience report. They showed an application they developed for the Android Developer Challenge called Mobile Zoo. Their baseline: &#8220;What&#8217;s here looks promising. Let&#8217;s see the devices!&#8221;</p>
<p>Brian Sletten&#8217;s presentation on data-driven applications was very interesting. I particularly liked the analogy between resampling music and data. </p>
<script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><div style="float: left; width: 140px; height: 21px; overflow: hidden; position: relative; left: 8px;"><script>//<![CDATA[
reddit_url="http://canoo.com/blog/2008/06/25/jazoon-08-day-i/";
//]]&gt;
</script><script language="javascript" src="http://reddit.com/button.js?t=1"></script></div>]]></content:encoded>
			<wfw:commentRss>http://canoo.com/blog/2008/06/25/jazoon-08-day-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rich(Mobile) != Rich(Desktop)</title>
		<link>http://canoo.com/blog/2008/01/16/richmobile-richdesktop/</link>
		<comments>http://canoo.com/blog/2008/01/16/richmobile-richdesktop/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 08:00:57 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[RIA4Mobiles]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>

		<guid isPermaLink="false">http://canoo.com/blog/2008/01/14/richmobile-richdesktop/</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2008/01/16/richmobile-richdesktop/";</script>Shortly before the end of last year, we completed a mobile demo application, which we used to analyze and investigate the status of Rich Internet Applications (RIA) technologies for mobile devices (what we will refer to as &#8220;RIA4Mobiles&#8221; within this blog post) .
The showcase application we developed describes the following scenario: field engineers use a [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2008/01/16/richmobile-richdesktop/";</script><p>Shortly before the end of last year, we completed a mobile demo application, which we used to analyze and investigate the status of Rich Internet Applications (RIA) technologies for mobile devices (what we will refer to as &#8220;<strong>RIA4Mobiles</strong>&#8221; within this blog post) .</p>
<p>The showcase application we developed describes the following scenario: field engineers use a mobile device to receive their daily work tasks or orders (called &#8220;mission&#8221; in our application) which they need to complete for that day and to communicate certain states such as &#8220;starting to work on mission X&#8221; or &#8220;completed mission Y&#8221; to a back office team application.  The field engineer can use the mobile device to book the time spent and material used for a certain mission, so that the back office team can directly process the billing once a mission has been completed. In addition, the back office team can send &#8220;high prio&#8221; missions to a specific field engineer.</p>
<p>After having a look at different architectural approaches (ranging from device-specific fat clients to browser-based generic Web applications), we decided to go with an <em>in-between</em> approach: a <a href="http://code.google.com/webtoolkit/">GWT</a> application tailored for mobile devices that runs in a generic, JavaScript-enabled mobile browser and connects to a server-side service infrastructure to fetch data and post back state changes. </p>
<p>For the target devices, we used a brand-new <a href="http://www.apple.com/iphone/">iPhone</a> and an older <a href="http://welcome.hp.com/country/us/en/prodserv/handheld.html">iPAQ</a> (about two years old, running Windows Mobile 2003). </p>
<p>The back office application is written in server-side Java, using <a href="http://www.canoo.com/ulc/">UltraLightClient</a> as the RIA technology. </p>
<p>Here is a screenshot of the mobile client:</p>
<p><img id="image173" src="http://canoo.com/blog/wp-content/uploads/2008/01/MobileClient.png" alt="Showcase application: mobile screen" /></p>
<p>Here is a screenshot of the corresponding back office application (click on the image to view a larger screenshot):</p>
<p><a href="http://canoo.com/blog/wp-content/uploads/2008/01/backofficeclient_large.png"><img id="image175" src="http://canoo.com/blog/wp-content/uploads/2008/01/backofficeclient_small.png" alt="Showcase application: Back office screen" /></a></p>
<p>Instead of going into the gory technical details here (we will do that in a future posting), let me discuss some of the lessons learned:</p>
<p>First, the approach chosen (GWT application + &#8220;Web services&#8221;) works for mobile applications. We were able to deliver the mobile application to the mobile device. Nevertheless, there are some shortcomings:</p>
<ul>
<li>whereas the generic, browser-based approach supports any device that hosts an up-to-date browser (with JavaScript support enabled), it also  prevents a tight integration into the device itself: the look and feel is not completely &#8220;native&#8221;, its usability may be different from the concepts known from other device-native applications, and the application shows a &#8220;low fidelity&#8221;. In addition, the reuse of existing device-specific applications such as map tools, address book or telephony application is either impossible or only achievable in a device-specific way (e.g. the iPhone supports dialing numbers from a website that are encoded as a URL with link type &#8220;tel://&#8221;, other devices may support the &#8220;callto://&#8221; link type, others may not support this functionality at all). A browser-based mobile application is somehow isolated from the device, running in its own world. This is especially irritating as two of the most current developments in the mobile world, <a href="http://code.google.com/android/">Google’s Android</a> and <a href="http://java.sun.com/javafx/mobile/">Sun’s Java FX Mobile</a>, propagate an application model that is based on the reuse of existing applications available on the mobile device.</li>
<li>one evil thing we know from the desktop world also holds true for the mobile world: <strong>browser hell</strong>. There is no „write once, run anywhere“ (not even with GWT’s cross-browser abstraction layer). This is due to the fact that there are various different mobile browser products and versions available on the market. Some of them are state-of-the-art and support a wide set of JavaScript and CSS features, others provide no JavaScript support at all (or only a very small subset of the language). Some of the good browsers are not available for free (such as Opera Mobile). Tweaking CSS properties and pixels was part of the daily business while developing the showcase application.</li>
<li>in mobile scenarios, (bad, broken) connectivity is an important topic, and so is offline capability. Thanks to the client-side JavaScript-based approach of GWT, offline &#8220;reading&#8221; is possible to a certain extent, but modifying data offline and synchronizinig the changes back to the server has very narrow limits in a browser-based world. Typically, there is no on-device persistent storage (such as a local database) available for browser-based application, as the browser builds some kind of a sandbox for that application. Ideas and projects such as <a href="http://gears.google.com/">Google Gears</a> aim to ease those limitations, but currently require the installation of  additional software (i.e. a browser plugin) on the mobile device. </li>
<li>even in times with high-end mobile devices such as the iPhone, performance issues on mobile devices are ubiquitous. The rendering performance is often poor, resulting in disturbing lags when rendering large option lists or tables (on the iPAQ device, even DOM manipulations on small HTML-based tables lead to unwanted &#8220;update effects&#8221;).</li>
</ul>
<p>In addition to these shortcomings, rooted in the architectural approach chosen for the showcase, another thing became obvious to us: <strong>Rich(Mobile) != Rich(Desktop)</strong>:</p>
<ul>
<li>one important difference when it comes to &#8220;rich&#8221;, especially related to the usability aspect of richness, is the fact that on mobile devices, users do not have a mouse pointer. Mobile users use either a pen, their fingers, or a navigation button (for devices without touch screens). These facilities reduce pointing precision. There is no &#8220;mouse move&#8221; equivalent as there is no difference between moving the pointer and activating the pointer (as soon as you touch the screen, an event is triggered). This reduces the number of available gestures and thus, prevents applications from using some of this gestures for interaction (e.g. hovering effects or tooltips are normally not supported on touch screen devices due to the lack of &#8220;mouse move&#8221; events). A further effect of the reduced set of useful gestures for mobile devices and the corresponding pointing devices is  that gestures often get &#8220;overloaded&#8221; (on the iPhone, for example, dragging means &#8220;scroll the web page&#8221;, and not &#8220;perform a drag and drop operation&#8221;).</li>
<li>the set of useful UI widgets is reduced as a consequence of the low-precision pointing device and the small screen size. Widgets such as spinners that allow toggling a value up and down using small arrows is not very usable on a mobile device, the same applies to scrolling in large lists (guess why the iPhone provides enhanced support for selecting a value from a combobox shown on a Web page). </li>
<li>the general layout-policy for mobile devices differs from desktop-based RIAs: whereas on desktop RIAs, layouts such as the dock layout are often used to provide as much flexibility to the user as possible and let the user choose almost any desired application with as little clicks as possible, mobile applications use a stack-based layout that limits the information displayed and the actions available to the user at a given moment. A mobile application needs to reduce the application context to the most important information and actions at any given time. This layout resembles the page-based approach of old-school Web applications that the one of modern RIAs.
</li>
</ul>
<p><strong>The bottom line:</strong> RIA4Mobiles developers will need to focus a lot more on usablility, device limitations and richness compared to the development of desktop RIAs in order to deliver highly usable, responsive and appealing mobile RIAs.</p>
<p>All in all, RIA4Mobiles is an exciting new application area. Stay tuned to hear more about our showcase application!</p>
<script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><div style="float: left; width: 140px; height: 21px; overflow: hidden; position: relative; left: 8px;"><script>//<![CDATA[
reddit_url="http://canoo.com/blog/2008/01/16/richmobile-richdesktop/";
//]]&gt;
</script><script language="javascript" src="http://reddit.com/button.js?t=1"></script></div>]]></content:encoded>
			<wfw:commentRss>http://canoo.com/blog/2008/01/16/richmobile-richdesktop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a Regular Website with the Google Web Toolkit &#8211; Part II</title>
		<link>http://canoo.com/blog/2007/04/18/building-a-regular-website-with-the-google-web-toolkit-part-ii/</link>
		<comments>http://canoo.com/blog/2007/04/18/building-a-regular-website-with-the-google-web-toolkit-part-ii/#comments</comments>
		<pubDate>Wed, 18 Apr 2007 09:45:34 +0000</pubDate>
		<dc:creator>danip</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[GWT]]></category>

		<guid isPermaLink="false">http://canoo.com/blog/2007/04/16/building-a-regular-website-with-the-google-web-toolkit-part-ii/</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2007/04/18/building-a-regular-website-with-the-google-web-toolkit-part-ii/";</script>Introduction
About a month ago I wrote about my experience when building a simple but configurable web site with help of the Google Web Toolkit (see Part I). I mentioned the hurdles that I encountered but also some motivating aspects when working with GWT.

An issue I haven&#8217;t reported on yet was my attempt to internationalize my [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2007/04/18/building-a-regular-website-with-the-google-web-toolkit-part-ii/";</script><h2>Introduction</h2>
<p>About a month ago I wrote about my experience when building a simple but configurable web site with help of the Google Web Toolkit (see <a href="http://canoo.com/blog/2007/03/13/building-a-regular-website-with-the-google-web-toolkit/">Part I</a>). I mentioned the hurdles that I encountered but also some motivating aspects when working with GWT.</p>
<p/>
An issue I haven&#8217;t reported on yet was my attempt to internationalize my GWT application. You might be surprised why this is even worth mentioning, since GWT includes I18N support. Well, let&#8217;s say it includes <strong><em>some</em></strong> I18N support &#8211; but it was not what I needed.</p>
<h2>Giving GWT&#8217;s I18N a Try</h2>
<p>The GWT developer guide explains the various I18N options of GWT (see <a href="http://code.google.com/webtoolkit/documentation/com.google.gwt.doc.DeveloperGuide.Internationalization.html">GWT I18N</a>) but all of them have one thing in common: The locale cannot be changed dynamically at runtime <strong>after</strong> a GWT application has been started. However, it is a common use case that you want to change an application&#8217;s locale at that point of time.</p>
<h2>Providing Truly Dynamic I18N</h2>
<p>Truly dynamic I18N means that use change the locale in the GUI at runtime. E.g., if the user changes a combo box entry, then all GUI labels magically obtain the newly localized values. To see what I mean, you may want to check out <a href="http://canoo.com/blog/wp-content/uploads/2007/03/org.canoo.gwt.sample.MySite/MySite.html">the result of my attempts</a>.</p>
<p/>
The way to solve this was to write my own (but simple) resource bundle API, which is similar<br />
to the one provided by the Java class java.util.ResourceBundle. Unfortunately, this requires quite some code including:</p>
<ul>
<li>a properties file reader,</li>
<li>a locale class,</li>
<li>a resource bundle loader.</li>
</ul>
<h2>The Resource Bundle Loader</h2>
<p>As it turned out, implementing the resource bundle loader was far from trivial. One of the resource bundle loader&#8217;s tasks is to load and cache a properties file from the server on the basis of a given locale. You can access a bundle entry with a key string in order to obtain the best possible localized result value. The means that the loader might have to access a chain of properties files according the chain of locales (from the most specific current locale to the default locale).</p>
<p/>
To implement the loading of properties files with GWT, one must use the class HTTPRequest, which offers an asynchronous request API for loading files from the server. Unfortunately, coordinating the chained download of properties files such as described above is rather difficult to implement with an asynchronous API. (See my last blog about <a href="http://canoo.com/blog/2007/03/13/building-a-regular-website-with-the-google-web-toolkit">infectious asynchronous APIs</a>.)</p>
<h2>Summary</h2>
<p>In the following I would like to give brief summary of my experiences with GWT:</p>
<p/>
<strong>Upsides:</strong></p>
<ul>
<li>I liked the general concept behind GWT and I think it is the (or &#8220;a&#8221;) way to go for proper software engineering in the AJAX space.</li>
<li>Getting in touch and getting familiar with GWT was easy enough and was great fun.</li>
<li>The compiler and the debugger seemed stable, work well and the compiler generates efficient code.</li>
</ul>
<p><strong>Downsides:</strong></p>
<ul>
<li>The widget library is far from complete and not engineered for extensions and reuse.</li>
<li>The asynchronous GWT APIs are often inconvenient &#8211; Google should ofter synchronous variants wherever possible.</li>
<li>Google&#8217;s I18N solution does not offer true dynamic locale changes. This is a serious drawback for many rich client applications.</li>
</ul>
<script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><div style="float: left; width: 140px; height: 21px; overflow: hidden; position: relative; left: 8px;"><script>//<![CDATA[
reddit_url="http://canoo.com/blog/2007/04/18/building-a-regular-website-with-the-google-web-toolkit-part-ii/";
//]]&gt;
</script><script language="javascript" src="http://reddit.com/button.js?t=1"></script></div>]]></content:encoded>
			<wfw:commentRss>http://canoo.com/blog/2007/04/18/building-a-regular-website-with-the-google-web-toolkit-part-ii/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Building a Regular Website with the Google Web Toolkit</title>
		<link>http://canoo.com/blog/2007/03/13/building-a-regular-website-with-the-google-web-toolkit/</link>
		<comments>http://canoo.com/blog/2007/03/13/building-a-regular-website-with-the-google-web-toolkit/#comments</comments>
		<pubDate>Tue, 13 Mar 2007 10:02:18 +0000</pubDate>
		<dc:creator>danip</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[GWT]]></category>

		<guid isPermaLink="false">http://canoo.com/blog/?p=11</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2007/03/13/building-a-regular-website-with-the-google-web-toolkit/";</script>The Idea
Many nice and home-grown websites contain a navigation bar. But without a special design tool a navigation bar is not easy to build because it typically involves JavaScript programming. My idea was to build a simple and convenient tool such that a non-technical person with basic knowledge about static HTML can easily include a [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://canoo.com/blog/2007/03/13/building-a-regular-website-with-the-google-web-toolkit/";</script><h2>The Idea</h2>
<p>Many nice and home-grown websites contain a navigation bar. But without a special design tool a navigation bar is not easy to build because it typically involves JavaScript programming. My idea was to build a simple and convenient tool such that a non-technical person with basic knowledge about static HTML can easily include a corresponding navigation bar in its pages.</p>
<p>The person configures the navigation bar by composing or adjusting a rather simple XML file. The HTML writer should not have to deal with server-side page scripting or anything a like. For the website to work, it should be sufficient to deploy the XML and a bunch of static HTML files along with some ready-made magic. Trying out the site should be as easy as double-clicking the main HTML file in the local file system.</p>
<p>I like Java and I did not want get my hands dirty with JavaScript and browser compatiblity issues. So how could I get the job done? Since I also like experimenting, I decided to give the GWT (the Google Web Toolkit) a go for the project.</p>
<p>When reading the GWT&#8217;s documentation, its seemed like the perfect choice for me: I program my navigation bar entirely in Java and in the end, it is all converted to a highly optimized and pure client-side JavaScript / HTML mash. Wow!</p>
<p>In the following, you can read about my related experience with the GWT and the many unexpected hurdles a had to take in order to reach my goal.</p>
<p>Here is a brief summary about the problems I encountered and my general impression, after playing with the GWT:</p>
<ul>
<li>The GWT misses (at least) some basic widgets, you may expect in an Ajax (library).</li>
<li>(At least some) of the existing widgets are difficult to extend.</li>
<li>The asynchronous programming model of the GWT (and Ajax in general) leads to problems,<br />
when creating higher level API. (You are forced to give it an asynchronous design, too.)</li>
<li>The GWT does not well support dynamic locale changes (details will follow in an upcoming blog entry).</li>
</ul>
<p>Although I was really enthusiastic about the GWT when I started, I have to admit that I got disappointed here and there.<br />
An upside is the GWT&#8217;s basic infrastructure (i.e. the compiler and the debugger), which seems very mature and stable.<br />
It&#8217;s really just the library that should be improved&#8230;</p>
<h2>Getting in Touch with the GWT</h2>
<p>If you are a reasonably experienced Java programmer, then getting started with the GWT is easy, and the quick results are motivating. So, after trying out some basic stuff, I wanted to make shure that the GWT API indeed allows me to realize my little project.</p>
<h2>The Navigation Bar Hassle</h2>
<p>The GWT library contains a widget, which is close to the kind of navigation bar I had in mind: the class <em><a href="http://code.google.com/webtoolkit/documentation/com.google.gwt.user.client.ui.TabPanel.html">com.google.gwt.user.client.ui.TabPanel</a></em>. Unfortunately, it allows for creating horzitontal navigation bars <strong>only</strong>.</p>
<p>When looking at the <a href="http://code.google.com/webtoolkit/documentation/examples/kitchensink/demo.html">GWT kitchen sink example</a>, it seems like there is a vertical navigation bar included &#8211; but that impression is misleading. The vertical navigation bar in the kitchen sink does not use a ready-made GWT widget. Instead, it is a custom built thing made out of a bunch of hyperlink objects (of type <em>com.google.gwt.user.client.ui.Hyperlink</em>)</p>
<p>I wondered why Google did not add a built-in vertical tab panel and so I began to read the source code of the<br />
<em>TabPanel</em> and the affiliated <em>TabBar</em> class. I could not find any good reason why this widget should not be vertical and so, I tried to subclass <em>TabPanel</em> in order to get a vertical version of it. Sadly, my attempt quickly came to a halt, because the <em>TabPanel</em> had not at all been created with extensibilty in mind. The first few lines of code of GWT&#8217;s <em>TabPanel</em> reads as follows:</p>
<p><pre><code>public class TabPanel ... {
...
private DeckPanel deck = new DeckPanel();
private TabBar tabBar = new TabBar();
private TabListenerCollection tabListeners;

/**
* Creates an empty tab panel.
*/
public TabPanel() {
VerticalPanel panel = new VerticalPanel();
panel.add(tabBar);
panel.add(deck);
...</code></pre><br />
The <em>TabPanel</em> is a composite widget, which consists of simpler widgets, namely a <a href="http://code.google.com/webtoolkit/documentation/com.google.gwt.user.client.ui.VerticalPanel.html">vertical panel</a>, a <a href="http://code.google.com/webtoolkit/documentation/com.google.gwt.user.client.ui.TabBar.html">tab bar</a> and a <a href="http://code.google.com/webtoolkit/documentation/com.google.gwt.user.client.ui.DeckPanel.html">deck panel</a>. However, given the code from above, none of these contained widgets can be exchanged by subclassing, and therefore, it is practically impossible to get a vertical tab panel by by subclassing <em>TabPanel</em>.</p>
<p>I felt disappointed: If the set of built-in widgets is small, then at least I expect a good degree of extensibilty of the corresponding framework.</p>
<p>So how did I get my vertical tab pane then? By <strong>copy and patch</strong>! I copied the entire <em>TabPanel</em> code and turned it into my so-called <em>FlexibleTabPanel</em> class.</p>
<p>Its first lines read as follows:</p>
<p><pre><code>public class FlexibleTabPanel extends Composite implements TabListener,
SourcesTabEvents, HasWidgets, IndexedPanel {

private final WidgetCollection children = new WidgetCollection(this);
private final DeckPanel deck = new DeckPanel();
private final FlexibleTabBar tabBar;
private TabListenerCollection tabListeners;

/**
* Creates an empty tab panel.
*/
public FlexibleTabPanel(boolean horizontal) {
Panel panel = createOuterPanel(horizontal);
tabBar = createTabBar(horizontal);

panel.add(tabBar);
panel.add(deck);
...</code></pre><br />
The constructor of <em>FlexibleTabPanel</em> obtains a <em>boolean</em>, which decides, if the resulting tab pane is vertical or horizontal. The methods <em>createOuterPanel()</em> and <em>createTabBar()</em> may be overriden. Depending on the <em>boolean</em> flag, they create widgets for either the horizontal or the vertical case.</p>
<p>As you might guess, I also had to copy and patch the class <em><a href="http://code.google.com/webtoolkit/documentation/com.google.gwt.user.client.ui.TabBar.html">com.google.gwt.user.client.ui.TabBar</a></em>. I even had to subclass (the standard GWT classes) <em>HorizontalPanel</em> and <em>VerticalPanel</em>: Both classes have certain methods in common but the GWT does not factor them out in a common superclass or super interface. However, the original <em>TabPanel</em> class counts on these methods with respect to <em>HorizontalPanel</em>. Since I wanted to use the corresponding code in <em>FlexibleTabPanel</em> for both the <em>HorizontalPanel</em> and <em>VerticalPanel</em>, I was forced to do the following:</p>
<ol>
<li>I created an interface, which contains the missing super class methods and it looks<br />
as follows:<br />
<pre><code>public interface FlexibleIndexedPanel extends IndexedPanel {
public void add(Widget w);
public void insert(Widget w, int beforeIndex);
public boolean remove(Widget index);
}</code></pre><br />
(<em><a href="http://code.google.com/webtoolkit/documentation/com.google.gwt.user.client.ui.IndexedPanel.html">IndexedPanel</a></em> is an existing interface of the GWT, which just lacks the methods from above.)</li>
<li>I subclassed <em>HorizontalPanel</em> and <em>VerticalPanel</em> in the following ways:<br />
<pre><code>public class FlexibleHorizontalPanel extends HorizontalPanel
implements FlexibleIndexedPanel {
}

public class FlexibleVerticalPanel extends VerticalPanel
implements FlexibleIndexedPanel {
}</code></pre>
</li>
</ol>
<p>The new classes <em>FlexibleHorizontalPanel</em> and <em>FlexibleVerticalPanel</em> offer the functionality needed in <em>FlexibleTabPanel</em>. So far I could not find any good reason, why the GWT does not share this functionality in a common super class of the vertical and horizontal panel already.</p>
<h2>Building the Builder</h2>
<h3>XML and Properties Files for Configuration</h3>
<p>As I mentioned in the beginning, I wanted the navigation bar to be configurable via an XML file. Essentially the XML file should determine the structure of the bar and its contents. I wrote a little interpreter, which parses a related XML file and and turns it into a widget object hierarchy. This is a similar approach as in frameworks such as <a href="http://www.swixml.org/">SwiXML</a> and <a href="http://ulc-community.canoo.com/snipsnap/space/ULC+XML">ULCXML</a>, but for my purpose, the navigation builder, as I called it, acts on a much smaller scale.</p>
<p>Here is a sample XML file that the navigation builder is able to digest:</p>
<p><tt><br />
&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;<br />
&lt;navigation&gt;<br />
&lt;file id="home" xhref="home.html" mce_href="home.html"    html="true"/&gt;<br />
&lt;file id="cv" xhref="cv.html" mce_href="cv.html"    html="true"/&gt;<br />
&lt;file id="concerts" xhref="concerts.html" mce_href="concerts.html"    html="true"/&gt;<br />
&lt;navigation id="gallery" orientation="vertical" default="true"&gt;<br />
&lt;file id="image1" xhref="image1.html" mce_href="image1.html"    html="true" default="true"/&gt;<br />
&lt;content id="image2"&gt;This image is not yet available.&lt;/content&gt;<br />
&lt;/navigation&gt;<br />
&lt;file id="contact" xhref="contact.html" mce_href="contact.html"    html="true"/&gt;<br />
&lt;/navigation&gt;<br />
</tt></p>
<p>Based on this file, the interpreter creates an outer navigation bar with five tabs. The first tab has the id <em>home</em>, and when selected, it displays the HTML file <em>home.html</em>. The next two entry work similarly. The fourth entry defines an inner navigation bar, which is vertical and contains two tabs itself: The first inner tab relates to the HTML file <em>image1.html</em> and the second one adds the text <em>This image is not yet available.</em> in place.</p>
<p>As you can see, it&#8217;s usually HTML files, which determine, what&#8217;s displayed upon tab selection. But where do the display names of the tabs actually come from? For reasons I will explain later, I moved all of these names to Java properties files. E.g. the properties file <em>navigation.properties</em> for the XML file from above may look as follows:</p>
<p><pre><code>home=Home
cv=CV
concerts=Concerts
gallery=Gallery
contact=Contact
image1=Image 1
image2=Image 2</code></pre></p>
<p>Every id defined in the XML file is referenced in the properties file and is associated with an English display text.</p>
<h3>Being Asynchronous is Contagious</h3>
<p>After that, it was time to build the navigation builder class itself. The GWT comes with a convenient<br />
DOM-based XML parser API and so, it was easy to write the interpreter code.<br />
Interestingly, the way to read a corresponding XML file with the GWT has a serious impact on the entire program structure.</p>
<p>Reading files inside a Web page is real Ajax functionality, and the related GWT API must be used as follows:</p>
<p><pre><code>HTTPRequest.asyncGet(&quot;myfileName&quot;, new ResponseTextHandler() {
public void onCompletion(String responseText) {
...
}
}</code></pre></p>
<p>The code loads the file <em>myfileName</em> via a relative URL and upon success, the contents of the file is passed in as a string to the <em>onCompletion()</em> method.<br />
Since the method <em>asyncGet()</em> returns its result via a callback, it is called <em>asynchronous</em>. The navigation builder uses <em>asyncGet()</em> and therefore its API became asynchronous too:</p>
<p><pre><code>NavigationBuilder builder = new NavigationBuilder(...);
builder.buildNavigation(
new NavigationBuildHandler() {
public void onBuilt(Widget widget) {
...
}

public void onFailure() {
...
}
});</code></pre><br />
Asynchronous APIs considerably change the structure of depending programs and in the example above, an asynchronous low level API &#8220;infected&#8221; a higher level API.<br />
In the context of the GWT this effect is hard to prevent, because the native<br />
execution environment (Java Script) has no thread concept and no thread synchronization mechanisms.</p>
<h3>Results</h3>
<p>After putting it all together, I finally got a first version of the navigation bar. <a href="http://canoo.com/blog/wp-content/uploads/2007/03/org.canoo.gwt.sample.MySite/MySite.html">Follow this link</a> to try out a corresponding example, which uses the XML file and the properties file from above.</p>
<p>The file <a href="http://canoo.com/blog/wp-content/uploads/2007/03/gwtsample1.zip">GWTSample1.zip</a> contains all the related source code.</p>
<p>Next week, I will talk about my adventures, when I tried to bring internationalization into the system. (Note that the code in the zip file contains the code for related feature already.)</p>
<script>var dzone_style="2";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><div style="float: left; width: 140px; height: 21px; overflow: hidden; position: relative; left: 8px;"><script>//<![CDATA[
reddit_url="http://canoo.com/blog/2007/03/13/building-a-regular-website-with-the-google-web-toolkit/";
//]]&gt;
</script><script language="javascript" src="http://reddit.com/button.js?t=1"></script></div>]]></content:encoded>
			<wfw:commentRss>http://canoo.com/blog/2007/03/13/building-a-regular-website-with-the-google-web-toolkit/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
