<?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>Pereira&#039;s blog &#187; WEB 2.0</title>
	<atom:link href="http://jpereira.eu/category/web-20/feed/" rel="self" type="application/rss+xml" />
	<link>http://jpereira.eu</link>
	<description>It&#039;s just that, a blog, my blog :)</description>
	<lastBuildDate>Wed, 09 May 2012 12:18:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Quick introduction to REST and JAX-RS</title>
		<link>http://jpereira.eu/2012/04/18/quick-introduction-to-rest-and-jax-rs/</link>
		<comments>http://jpereira.eu/2012/04/18/quick-introduction-to-rest-and-jax-rs/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 22:38:43 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Architectures]]></category>
		<category><![CDATA[WEB 2.0]]></category>
		<category><![CDATA[Agile Developemnt]]></category>
		<category><![CDATA[Architectures]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=520</guid>
		<description><![CDATA[Here are some slides introducing to REST world. Examples are using JAX-RS (JSR 311). If we&#8217;re moving to the cloud-era, the undestanding of this architecture style is essential. In the cloud we are presented with services (Storage, Search, Graph, Geolocation, &#8230;) that we can and should use to build applications. Almost all of these services, [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some slides introducing to REST world. Examples are using JAX-RS (JSR 311).</p>
<p>If we&#8217;re moving to the cloud-era, the undestanding of this architecture style is essential. In the cloud we are presented with services (Storage, Search, Graph, Geolocation, &#8230;) that we can and should use to build applications. Almost all of these services, available  in the cloud, provide some kind of interface and happens that, this  interfaces is, generally, a RESTful Web Service. If I want collaborate with these services I must talk the same language!! Moreover, exploring this architectural style in new applications opens the door for realy distributed and scalable systems, while the simplicity is kept high!</p>
<p>Here the slides:</p>
<div id="__ss_12595104" style="width: 425px;"><strong style="display: block; margin: 12px 0 4px;"><a title="Restful web services" href="http://www.slideshare.net/joaomiguel.pereira/restful-web-services-12595104">Restful web services</a></strong><object id="__sse12595104" width="425" height="355" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=restfulwebservices-120418171743-phpapp01&amp;stripped_title=restful-web-services-12595104&amp;userName=joaomiguel.pereira" /><param name="allowscriptaccess" value="always" /><param name="allowfullscreen" value="true" /><embed id="__sse12595104" width="425" height="355" type="application/x-shockwave-flash" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=restfulwebservices-120418171743-phpapp01&amp;stripped_title=restful-web-services-12595104&amp;userName=joaomiguel.pereira" allowFullScreen="true" allowScriptAccess="always" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" /></object></p>
<div style="padding: 5px 0 12px;">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/joaomiguel.pereira">Joao Pereira</a>.</div>
</div>
<p>PDF can be downloaded from <a href="http://www.box.com/s/a91c32b941eb96443273" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2012/04/18/quick-introduction-to-rest-and-jax-rs/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Software Architecture disruption?</title>
		<link>http://jpereira.eu/2012/04/18/software-architecture-disruption/</link>
		<comments>http://jpereira.eu/2012/04/18/software-architecture-disruption/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 10:32:17 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Architectures]]></category>
		<category><![CDATA[WEB 2.0]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[Agile Developemnt]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Social Networks]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=517</guid>
		<description><![CDATA[:Adrian Colyer is a smart guy and he  put together, in a talk, what software architectures will look like for the next years. True is, most of the services you&#8217;re using online today follow these architecture principles. Nothing new, thought. Nothing in this architecture is can go wrong,  it&#8217;s so simple! This type of architecture [...]]]></description>
			<content:encoded><![CDATA[<p>:<a href="http://twitter.com/#!/adriancolyer" target="_blank">Adrian Colyer</a> is a smart guy and he  put together, in a talk, what software architectures will look like for the next years. True is, most of the services you&#8217;re using online today follow these architecture principles. Nothing new, thought.</p>
<p>Nothing in this architecture is can go wrong,  it&#8217;s so simple! This type of architecture is the perfect fit for this ubiquitous platform that is Internet.</p>
<p>Btw,  <a href="http://www.springsource.org/" target="_blank">SpringSource </a>makes it really easy to develop applications in this way, just look to <a href="http://www.springsource.org/spring-integration" target="_blank">Spring Integration</a> project, for example. They have a plenty of projects, built on top of Spring, that makes development of this type of architectures more, and more fun and easy.</p>
<p>(Ignore the sound problems at the beginning <img src='http://jpereira.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )<br />
<iframe src="http://www.youtube.com/embed/axOPJbrIjkY" frameborder="0" width="560" height="315"></iframe></p>
<p>Contrast this with traditional &#8220;enterprise&#8221; architectures. Which side of the fence you want to be?</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2012/04/18/software-architecture-disruption/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GWT Quickstart Project with Maven+GWT2.3+GIN1.5</title>
		<link>http://jpereira.eu/2011/07/14/gwt-quickstart-project-with-mavengwt2-3gin1-5/</link>
		<comments>http://jpereira.eu/2011/07/14/gwt-quickstart-project-with-mavengwt2-3gin1-5/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 13:57:01 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[WEB 2.0]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=424</guid>
		<description><![CDATA[This post will show you, and remind me in the future, how to quickly setup a GWT 2.3 project with maven and GIN 1.5.]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>Been a while&#8230; This post will show you, and remind me in the future, how to quickly setup a</p>
<p><a href="http://code.google.com/webtoolkit/">GWT 2.3</a> project with <a href="http://maven.apache.org/">Maven2</a> and <a href="http://code.google.com/p/google-gin/">GIN 1.5</a>. I&#8217;m using Ubuntu, but the essential steps should be the same in any operating system.</p>
<p>Let&#8217;s start.</p>
<p>Assuming you have maven installed, just run:</p>
<pre class="brush: plain; title: ; notranslate">
mvn archetype:generate -DarchetypeRepository=repo1.maven.org -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.3.0-1
</pre>
<p>Then, enter the details for you new GWT 2.3 project. Don&#8217;t forget that the property for &#8216;module&#8217; should be a valid Java Class name, so use camel case when setting the name of module.<br />
My configurations are something like:</p>
<pre class="brush: plain; title: ; notranslate">
Define value for property 'groupId': : eu.jpereira.gwt
Define value for property 'artifactId': : quickstart
Define value for property 'version': 1.0-SNAPSHOT:
Define value for property 'package': eu.jpereira.gwt:
Define value for property 'module': : Quickstart
Confirm properties configuration:
groupId: eu.jpereira.gwt
artifactId: quickstart
version: 1.0-SNAPSHOT
package: eu.jpereira.gwt
module: Quickstart
</pre>
<p>Now, we just need to add the dependency to GIN 1.5. Open the generated POM for the Quickstart project and add the dependency for GIN 1.5:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- GIN Stuff --&gt;
&lt;dependency&gt;
	&lt;groupId&gt;com.google.gwt.inject&lt;/groupId&gt;
	&lt;artifactId&gt;gin&lt;/artifactId&gt;
	&lt;version&gt;1.5.0&lt;/version&gt;
	&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
</pre>
<p>Now you have a GWT 2.3 project with GIN 1.5 and Maven.<br />
To finalize, let just remind how to setup GIN with the GWT project.<br />
Generate the eclipse project:</p>
<pre class="brush: plain; title: ; notranslate">
mvn eclipse:eclipse gwt:eclipse
</pre>
<p>Open the project in eclipse and edit the *.gwt.xml (in my case, this is the file Quickstart.gwt.xml) file, located under &#8220;src/main/resources/&#8221; to import the GIN module:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;inherits name=&quot;com.google.gwt.inject.Inject&quot; /&gt;
</pre>
<p>Create the GinModule, the class file that will configure the dependency injection for your application. You can have any number of GinModules. Check the documentation here: <a href="http://code.google.com/p/google-gin/wiki/GinTutorial">http://code.google.com/p/google-gin/wiki/GinTutorial</a><br />
I like to keep everything related to GIn under the package *.client.gin. My Module is this:</p>
<pre class="brush: java; title: ; notranslate">
package eu.jpereira.gwt.client.gin;

import com.google.gwt.inject.client.AbstractGinModule;
import com.google.inject.Singleton;
import eu.jpereira.gwt.client.QuaickstartApplication;

public class QuickstartGinModule extends AbstractGinModule {

	@Override
	protected void configure() {
		bind(QuaickstartApplication.class).in(Singleton.class);

	}
}
</pre>
<p>Here I&#8217;m only binding the QuickstartApplication object, which is my main application, like this:</p>
<pre class="brush: java; title: ; notranslate">
package eu.jpereira.gwt.client;

import com.google.gwt.user.client.Window;

public class QuaickstartApplication {

	public void run() {
		Window.alert(&quot;Hello World!!!&quot;);
	}
}
</pre>
<p>Back to Gin setup, let&#8217;s create the Ginjector. Create a new Interface that extends from Ginjector:</p>
<pre class="brush: java; title: ; notranslate">
package eu.jpereira.gwt.client.gin;

import com.google.gwt.inject.client.GinModules;
import com.google.gwt.inject.client.Ginjector;
import eu.jpereira.gwt.client.QuickstartApplication;
@GinModules(QuickstartGinModule.class)
public interface QuickstartInjector extends Ginjector{
	QuickstartApplication getQuickstartApplication();
}
</pre>
<p>Finally, it&#8217;s time to use it. In the Quickstart.java, which contains the entry point to the application, remove everything, create the injector and start your application.</p>
<pre class="brush: java; title: ; notranslate">
package eu.jpereira.gwt.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;

import eu.jpereira.gwt.client.gin.QuickstartInjector;

/**
 * Entry point classes define &lt;code&gt;onModuleLoad()&lt;/code&gt;.
 */
public class Quickstart implements EntryPoint {

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		QuickstartInjector injector = GWT.create(QuickstartInjector.class);
		injector.getQuickstartApplication().run();

	}

}
</pre>
<p>Now, run the application with:</p>
<pre class="brush: plain; title: ; notranslate">
mvn gwt:run
</pre>
<p>And you should see the &#8220;Hello World!!&#8221; alert.</p>
<p>BTW, you can download the project <a href="http://jpereira.eu/wp-content/uploads/2011/07/quickstart.zip">here</a>.</p>
<p>Happy coding!!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/07/14/gwt-quickstart-project-with-mavengwt2-3gin1-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The problem with Java Web development frameworks is&#8230;</title>
		<link>http://jpereira.eu/2011/02/08/the-problem-with-java-web-development-frameworks-is/</link>
		<comments>http://jpereira.eu/2011/02/08/the-problem-with-java-web-development-frameworks-is/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 14:30:08 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[WEB 2.0]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=384</guid>
		<description><![CDATA[Well, from my point of view, the problem of Java Web development frameworks is that there are too many. Each one has its strengths and weaknesses, like anything else. I&#8217;m excluding those that are proprietary and you have to pay to use them. Really, why would people pay for such kind of thing? Focusing on [...]]]></description>
			<content:encoded><![CDATA[<p>Well, from my point of view, the problem of Java Web development frameworks is that there are too many. Each one has its strengths and weaknesses, like anything else. I&#8217;m excluding those that are proprietary and you have to pay to use them. Really, why would people pay for such kind of thing? </p>
<p>Focusing on what is open source, you just need to see those supported by Apache: <a href="http://projects.apache.org/indexes/category.html#web-framework">http://projects.apache.org/indexes/category.html#web-framework</a> </p>
<p>Then you can see a list of Java web development frameworks (result of a Google search):<br />
<a href="http://java-source.net/open-source/web-frameworks">http://java-source.net/open-source/web-frameworks </a></p>
<p>There&#8217;s are so many and the community does not focus on building a complete Java Web Development Framework. The one I like more is <a href="http://www.playframework.org/">Play! Framework</a> because it&#8217;s a complete stack of java technologies that really help the development of web apps and it borrows many concepts from Ruby on Rails, which it&#8217;s my favorite.</p>
<p>I don&#8217;t know every Java web development framework, of course, and each must have their strengths and serve different purposes, but my feeling is that if there were only a few, then the community will focuses on improving those and we&#8217;ll end with a truly good framework.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/02/08/the-problem-with-java-web-development-frameworks-is/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Yeahh, I&#8217;m building it with enterprise ready technologies&#8230; who cares?</title>
		<link>http://jpereira.eu/2011/02/05/yeahh-ia-building-it-with-enterprise-grade-technologies-who-cares/</link>
		<comments>http://jpereira.eu/2011/02/05/yeahh-ia-building-it-with-enterprise-grade-technologies-who-cares/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 14:45:57 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[WEB 2.0]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=372</guid>
		<description><![CDATA[If you have an web product idea and want to test it, i.e. put it in front of your users, what it&#8217;s the most critical aspect to consider first? I usually get my head into a conflict, because I&#8217;m used to work with the so-called &#8220;enterprise ready technologies&#8221;, namely JEE. My mind if formatted to [...]]]></description>
			<content:encoded><![CDATA[<p>If you have an web product idea and want to test it, i.e. put it in front of your users, what it&#8217;s the most critical aspect to consider first? I usually get my head into a conflict, because I&#8217;m used to work with the so-called &#8220;enterprise ready technologies&#8221;, namely JEE.  My mind if formatted to think about all aspects that a good enterprise product should have.  I start giving more attention to a set of quality attributes like performance, usability, reusability, testability, portability, modifiability, etc, etc, and give less attention to one critical aspect, if I want to get a product in front of the users fast: productivity.</p>
<p>So, I start looking to what is out there that is enterprise ready, like EJBs, JSF, Hibernate, JBoss, Tomcat, whatever, and start getting the pieces together&#8230;. out there in the world there was some a guy with the same product idea, but  considered first the productivity aspect of the equation and started to materialize the idea with, let&#8217;s say, Ruby on Rails&#8230;. guess who&#8217;s the winner?</p>
<p>I&#8217;m not against the use of JEE, of course, I just think that in some cases it does not make sense. I also have this false argument in my mind: What if I start building it with PHP and then hit a performance problem with my 1Million users? Well, If I ever had one million users, I&#8217;ll be happy to deal with these performance issues <img src='http://jpereira.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/02/05/yeahh-ia-building-it-with-enterprise-grade-technologies-who-cares/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Where’s my Java reflection?, Part II</title>
		<link>http://jpereira.eu/2011/01/30/where%e2%80%99s-my-java-reflection-part-ii/</link>
		<comments>http://jpereira.eu/2011/01/30/where%e2%80%99s-my-java-reflection-part-ii/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 18:45:08 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[WEB 2.0]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=364</guid>
		<description><![CDATA[Just to give the final implementation started in &#8220;Where&#8217;s my Java reflection&#8220;, here it goes the implementation of the generator for the method bindErrors (check last post &#8220;Where&#8217;s my Java reflection&#8220; to get into context): Again, hope it helps anyone.]]></description>
			<content:encoded><![CDATA[<p>Just to give the final implementation started in &#8220;<a href="http://jpereira.eu/2011/01/30/wheres-my-java-reflection/">Where&#8217;s my Java reflection</a>&#8220;, here it goes the implementation of the generator for the method bindErrors (check last post &#8220;<a href="http://jpereira.eu/2011/01/30/wheres-my-java-reflection/">Where&#8217;s my Java reflection</a>&#8220; to get into context):</p>
<pre class="brush: java; title: ; notranslate">
private void composeBindErrorsMethod(TreeLogger logger,
			SourceWriter sourceWriter, TypeOracle typeOracle) {

		sourceWriter.println(&quot;public void bindErrors(&quot;
				+ parameterizedType.getQualifiedSourceName()
				+ &quot; object, Map&lt;String, List&lt;String&gt;&gt; errors) {&quot;);

		// Get the fields declared in the parameterized type
		JField[] fields = parameterizedType.getFields();
		for (JField field : fields) {

			JClassType classType = field.getType().isClass();
			if (classType != null) {

				JClassType erroableType = typeOracle.findType(Errorable.class
						.getName());

				if (classType.isAssignableTo(erroableType)) {

					sourceWriter.println(&quot;if (errors.containsKey(\&quot;&quot;
							+ field.getName() + &quot;\&quot;)){&quot;);
					sourceWriter.println(&quot;object.&quot; + field.getName()
							+ &quot;.setErrors(errors.get(\&quot;&quot; + field.getName()
							+ &quot;\&quot;));&quot;);
					sourceWriter.println(&quot;}&quot;);

				}
			}

		}
		sourceWriter.println(&quot;}&quot;);
</pre>
<p>Again, hope it helps anyone.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/01/30/where%e2%80%99s-my-java-reflection-part-ii/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Where&#8217;s my Java reflection?</title>
		<link>http://jpereira.eu/2011/01/30/wheres-my-java-reflection/</link>
		<comments>http://jpereira.eu/2011/01/30/wheres-my-java-reflection/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 17:57:47 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[WEB 2.0]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=353</guid>
		<description><![CDATA[Some people like it, others don&#8217;t. I like it, it&#8217;s so cool to make generic code, but as I &#8216;ve been experimenting with GTW to know it&#8217;s capabilities I found that GWT does not support Reflection. It uses instead a mechanism called Deffered Binding to overcome the lack of reflection. When doing some kind of [...]]]></description>
			<content:encoded><![CDATA[<p>Some people like it, others don&#8217;t. I like it, it&#8217;s so cool to make generic code, but as I &#8216;ve been experimenting with <a href="http://code.google.com/webtoolkit/">GTW</a> to know it&#8217;s capabilities I found that GWT does not support <a href="http://java.sun.com/developer/technicalArticles/ALT/Reflection/">Reflection</a>. It uses instead a mechanism called <a href="http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsDeferred.html">Deffered Binding</a> to overcome the lack of reflection.</p>
<p>When doing some kind of framework code with GWT, soon you&#8217;ll realize that you need reflection, as I did. Bad luck, you&#8217;ll have to dig into the underground features of GWT, namely deferred bindings and generators. You can learn the theoretical traits of Deferred Bindings in the documentation: <a href="http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsDeferred.html">http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsDeferred.html</a></p>
<p>Let me explain my scenario.</p>
<p><span id="more-353"></span></p>
<p>I do all client/server communication using <a href="http://www.json.org/">JSON</a>, and the form field errors are returned from the server in JSON like this:</p>
<pre class="brush: plain; title: ; notranslate">
{&quot;errors&quot;: {&quot;name&quot;: [&quot;Error 1 on field name&quot;,  &quot;Error 1 on field name&quot;], &quot;email:  [&quot;Error 1 on field email&quot;,  &quot;Error 1 on field email&quot;]}, &quot;_errorMessage&quot;: &quot;Could not save the record due validation errors&quot;}
</pre>
<p>My form editor at the GWT side, has some kind of Editors for each field of the form that implements an interface like this:</p>
<pre class="brush: java; title: ; notranslate">
public interface Errorable {
	public void setError();
	public void setError(String message);
	public void setErrors(List&lt;String&gt; messages);
	public void clearErrors();
	public boolean hasErrors();
}
</pre>
<p>My form component has something like this:</p>
<pre class="brush: java; title: ; notranslate">
public class UserEditor extends Composite implements CompositeEditor&lt;User&gt; {

	@UiField
	TextBoxEditor name;

	@UiField
	TextBoxEditor email;
         //Rest of the code

	public void setFieldErrors(Map&lt;String, List&lt;String&gt;&gt; fieldErrors) {

		//Bind error fields
	}

}
</pre>
<p>TextEditor class implements the interface Errorable and the implementation of setErrors(List messages) simply shows the validation errors underneath the text box, the usual stuff&#8230;</p>
<p>The UserEditor::setFieldErrors(Map&gt; fieldErrors) get a Map produced from the JSON response, with the name of the field as key and a list of Strings representing each error in the field, and show the errors for the corresponding field in the UserEditor</p>
<p>My problem is with the implementation of UserEditor::setFieldErrors(Map&gt; fieldErrors) , I did&#8217;n want to do something like this:</p>
<pre class="brush: java; title: ; notranslate">
	public void setFieldErrors(Map&lt;String, List&lt;String&gt;&gt; fieldErrors) {

		//Bind error fields
		if ( fieldErrors.containsKey(&quot;name&quot;)) {
			name.setErrors(fieldErrors.get(&quot;name&quot;));
		}

		if ( fieldErrors.containsKey(&quot;email&quot;)) {
			name.setErrors(fieldErrors.get(&quot;email&quot;));
		}

	}
</pre>
<p>This could be a small amount of code now, but for a bigger application this is too much code I have to write by hand. So, here was where I needed the Java reflection. I needed to go through each field of FormEditor and find the members that implements the Erroable interface and check if the Map has a key with the same name and the call the setErros(List) on that members&#8230; you get it, right?</p>
<p>This could be done in runtime if I have access to Java reflection features in GWT, but I don&#8217;t and what I can have in GWT is code generation at compile time, so the solution to the problem can be slightly different than doing it with Java Reflection, but If I can generate that boilerplate code it would be great.</p>
<p>From here I digged into GWT code generation, and borrow some ideas from the <a href="http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html">UIBinder</a>.</p>
<p>My UserEditor.java has now something like this:</p>
<pre class="brush: java; title: ; notranslate">
public class UserEditor extends Composite implements CompositeEditor&lt;User&gt; {

private static UserEditorErrorBinder errorBinder = GWT
			.create(UserEditorErrorBinder.class);

interface UserEditorErrorBinder extends ErrorBinder&lt;UserEditor&gt; {

	}
}
</pre>
<p>The  ErrorBinder interface is defined as:</p>
<pre class="brush: java; title: ; notranslate">
public interface ErrorBinder&lt;T&gt; {
	public void bindErrors(T editor, Map&lt;String, List&lt;String&gt;&gt; errors);
}
</pre>
<p>Now I have to implement one generator that generate the code that implements  the method bindErrors with my desired logic.</p>
<p>After solving many puzzles, I came out with the this generator code that you can borrow to do your own generators in GWT:</p>
<pre class="brush: java; title: ; notranslate">
public class ErrorBinderGenerator extends Generator {

	private String implPackageName;

	private String implTypeName;
	private JClassType parameterizedType;

	public String generate(TreeLogger logger, GeneratorContext context,
			String requestedClass) throws UnableToCompleteException {

		TypeOracle typeOracle = context.getTypeOracle();

		JClassType objectType = typeOracle.findType(requestedClass);
		if (objectType == null) {
			logger.log(TreeLogger.ERROR, &quot;Could not find type: &quot;
					+ requestedClass);
			throw new UnableToCompleteException();
		}

		implTypeName = objectType.getSimpleSourceName() + &quot;Impl&quot;;

		implPackageName = objectType.getPackage().getName();

		JClassType[] implementedTypes = objectType.getImplementedInterfaces();

		// Can only implement one interface
		if (implementedTypes == null
				|| implementedTypes.length != 1
				|| !implementedTypes[0].getQualifiedSourceName().equals(
						ErrorBinder.class.getName())) {
			logger.log(TreeLogger.ERROR, &quot;The type: &quot; + requestedClass
					+ &quot; Must implement only one interface: &quot;
					+ ErrorBinder.class.getName());
			throw new UnableToCompleteException();
		}

		// Get parameterized type
		JParameterizedType parameterType = implementedTypes[0]
				.isParameterized();
		if (parameterType == null) {
			logger.log(TreeLogger.ERROR, &quot;The type: &quot; + requestedClass
					+ &quot; Must implement only one parameterized interface: &quot;
					+ ErrorBinder.class.getName());
			throw new UnableToCompleteException();
		}

		if (parameterType.getTypeArgs() == null

		|| parameterType.getTypeArgs().length != 1) {
			logger.log(TreeLogger.ERROR, &quot;The type: &quot; + requestedClass
					+ &quot; Must implement only one parameterized interface: &quot;
					+ ErrorBinder.class.getName() + &quot; with only onde Parameter&quot;);
			throw new UnableToCompleteException();

		}

		parameterizedType = parameterType.getTypeArgs()[0];

		ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(
				implPackageName, implTypeName);

		composerFactory.addImport(Map.class.getCanonicalName());
		composerFactory.addImport(List.class.getCanonicalName());
		composerFactory.addImplementedInterface(objectType
				.getQualifiedSourceName());

		PrintWriter printWriter = context.tryCreate(logger, implPackageName,
				implTypeName);
		if (printWriter != null) {

			SourceWriter sourceWriter = composerFactory.createSourceWriter(
					context, printWriter);

			composeBindErrorsMethod(sourceWriter);
			sourceWriter.commit(logger);

		}
		return implPackageName + &quot;.&quot; + implTypeName;
	}

	private void composeBindErrorsMethod(SourceWriter sourceWriter) {

		sourceWriter.print(&quot;public void bindErrors(&quot;
				+ parameterizedType.getQualifiedSourceName()
				+ &quot; erroable, Map&lt;String, List&lt;String&gt;&gt; errors) {&quot;);
		sourceWriter.print(&quot;  System.out.println(\&quot;Implement it now:)\&quot;);&quot;);
		sourceWriter.print(&quot;}&quot;);

	}
}
</pre>
<p>Now I have only to generate the code for bindErrors and implement the setFiledErrors method in my UserEditor like this:</p>
<pre class="brush: java; title: ; notranslate">
	public void setFieldErrors(Map&lt;String, List&lt;String&gt;&gt; fieldErrors) {
		errorBinder.bindErrors(this, fieldErrors);
	}
</pre>
<p>I hope this can help someone to bootstrap their own GWT generators.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/01/30/wheres-my-java-reflection/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Set focus on first input of a form</title>
		<link>http://jpereira.eu/2010/10/16/set-focus-on-first-input-of-a-form/</link>
		<comments>http://jpereira.eu/2010/10/16/set-focus-on-first-input-of-a-form/#comments</comments>
		<pubDate>Sat, 16 Oct 2010 21:58:46 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[WEB 2.0]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=296</guid>
		<description><![CDATA[Isn&#8217;t annoying when you open a web page with a form and then have to click on the first input to start entering our data? Well, it&#8217;s so easy to make this automatically with Javascript and JQuery&#8230;]]></description>
			<content:encoded><![CDATA[<p>Isn&#8217;t annoying when you open a web page with a form and then have  to click on the first input to start entering our data?</p>
<p>Well, it&#8217;s so easy to make this automatically with Javascript and <a href="http://jquery.com/">JQuery</a>&#8230;</p>
<pre class="brush: jscript; title: ; notranslate">
$(&quot;input:visible:enabled:first&quot;).focus();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2010/10/16/set-focus-on-first-input-of-a-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tenham cuidado com o que partilham nas redes Sociais</title>
		<link>http://jpereira.eu/2010/03/25/tenham-muito-cuidado-com-o-que-partilham-nas-redes-sociais/</link>
		<comments>http://jpereira.eu/2010/03/25/tenham-muito-cuidado-com-o-que-partilham-nas-redes-sociais/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 21:30:14 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[WEB 2.0]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=236</guid>
		<description><![CDATA[Há uns dias atrás vi os meus streams do Facebook, Twitter e Buzz cheios de mensagens acerca de subscrições que fiz a alguns canais do Youtube. Acredito que para quem viu esse fluxo de mensagens foi um grande desprazer. Também foi para mim porque quando integrei estas contas (Youtube, Buzz, Twitter e Facebook) não pensei [...]]]></description>
			<content:encoded><![CDATA[<p>Há uns dias atrás vi os meus streams do Facebook, Twitter e Buzz cheios de mensagens acerca de subscrições que fiz a alguns canais do Youtube. Acredito que para quem viu esse fluxo de mensagens foi um grande desprazer. Também foi para mim porque quando integrei estas contas (Youtube, Buzz, Twitter e Facebook) não pensei muito no assunto e devia-me ter precavido destas situações.</p>
<p><a href="http://jpereira.eu/wp-content/uploads/2010/03/flood.jpg"><img class="size-full wp-image-237 alignleft" title="flood" src="http://jpereira.eu/wp-content/uploads/2010/03/flood.jpg" alt="flood" width="244" height="374" /></a>Pior ainda, é que algumas das mensagens estavam duplicadas (Português e Inglês), como podem ver ali na imagem à esquerda.</p>
<p>Mas há quem faça pior. Há quem insista em partilhar tudo nas redes sociais. Por vezes parece que estou a ver a caixa de entrada do email de algumas pessoas, se me enviarem o número do cartão de crédito agradecia <img src='http://jpereira.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>No Google Buzz, que estou a ponderar desactivar, recebi a seguinte mensagem do stream de alguém:</p>
<blockquote><p>Alguém quer lhe conhecer no Badoo!</p>
<p>Outra pessoa por perto quer lhe conhecer. Vá até o Badoo e veja se a atração é mútua. Decida quem você quer conhecer!</p>
<p>http://ping.fm/&#8212;&#8211;</p>
<p>Obrigado,<br />
A Equipe Badoo</p>
<p>Esta é uma mensagem de envio somente. Respostas a esta mensagem não são monitoradas ou respondidas.<br />
Você recebeu esta mensagem como um usuário registrado no ,<br />
para controlar que emails você recebe, por favor, modifique as suas configurações:</p>
<p>http://ping.fm/&#8212;-</p></blockquote>
<p>WTF? Então só para passar o tempo, segui o primeiro link e qual é a minha surpresa que estava agora na posse de uma conta desse serviço (Badoo), com acesso à conta por completo&#8230; pena não se algo que me interessasse mais <img src='http://jpereira.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Já não é a primeira vez que isto me acontece. Da última vez foi alguém, com o mesmo nome que eu e provavelmente com um endereço de email muito parecido, que se enganou a introduzir o email no Hi5 e lá fiquei com acesso completo à conta do rapaz&#8230;</p>
<p>Se quiserem dar acesso às vossas contas de serviços de redes sociais e outros, utilizem um serviço que publique a vossa caixa de correio no stream do Buzz e outros streams.</p>
<p>Ficam avisados <img src='http://jpereira.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2010/03/25/tenham-muito-cuidado-com-o-que-partilham-nas-redes-sociais/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A TMN ainda nÃ£o percebeu o Twitter</title>
		<link>http://jpereira.eu/2009/12/23/as-tmn-ainda-nao-percebeu-o-twitter/</link>
		<comments>http://jpereira.eu/2009/12/23/as-tmn-ainda-nao-percebeu-o-twitter/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 18:16:21 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[WEB 2.0]]></category>
		<category><![CDATA[Estratégia]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=222</guid>
		<description><![CDATA[Um cliente liga para o 1696 da TMN e diz: Cliente: queria saber qual Ã© o melhor plano para acesso Ã  internet atravÃ©s do telemÃ³vel sem carregamentos obrigatÃ³rios. TMN: Zzzzz!! Zzzzz!! Cliente: estÃ£o-me a ouvir? TMN: Zzzzzz!! Zzzzz!! Isto nÃ£o aconteceu com o 1696 mas aconteceu com o Twitter. A TMN tem uma conta do [...]]]></description>
			<content:encoded><![CDATA[<p>Um cliente liga para o 1696 da TMN e diz:</p>
<p><strong>Cliente</strong>: queria saber qual Ã© o melhor plano para acesso Ã  internet atravÃ©s do telemÃ³vel sem carregamentos obrigatÃ³rios.</p>
<p><strong>TMN</strong>: Zzzzz!! Zzzzz!!</p>
<p><strong>Cliente</strong>: estÃ£o-me a ouvir?</p>
<p><strong>TMN</strong>: Zzzzzz!! Zzzzz!!</p>
<p>Isto nÃ£o aconteceu com o 1696 mas aconteceu com o Twitter. A TMN tem uma conta do twitter @tmn_pt, mas nÃ£o responde a estas questÃµes atravÃ©s do Twitter&#8230;. NÃ£o sei se eles querem propositadamente ignorar este canal de comunicaÃ§Ã£o ou entÃ£o nÃ£o perceberam ainda que o Twitter tambÃ©m serve para eles se relacionarem com os clientes e nÃ£o apenas para fazer publicidade.</p>
<p><img class="alignnone size-full wp-image-223" title="twitter_tmn" src="http://jpereira.eu/wp-content/uploads/2009/12/twitter_tmn.png" alt="twitter_tmn" width="607" height="339" /></p>
<p><a href="http://twitter.com/joaomrpereira/statuses/6836740450">http://twitter.com/joaomrpereira/statuses/6836740450</a></p>
<p>O que acham? Acham que a TMN poderia usar o Twitter sem ser apenas para fazer publicidade mas tambÃ©m para responder a questÃµes dos clientes?</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2009/12/23/as-tmn-ainda-nao-percebeu-o-twitter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
