<?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>GWT Tutorial</title>
	<atom:link href="http://www.gwttutorial.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.gwttutorial.com</link>
	<description>A GWT Tutorial For GWT Development</description>
	<lastBuildDate>Wed, 05 Sep 2012 15:49:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>GWT MVP Pattern</title>
		<link>http://www.gwttutorial.com/gwt-development/gwt-mvp-pattern</link>
		<comments>http://www.gwttutorial.com/gwt-development/gwt-mvp-pattern#comments</comments>
		<pubDate>Wed, 05 Sep 2012 15:49:46 +0000</pubDate>
		<dc:creator>Jeff Richley</dc:creator>
				<category><![CDATA[GWT Development]]></category>
		<category><![CDATA[GOF]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[GWT MVP Pattern]]></category>
		<category><![CDATA[Model]]></category>
		<category><![CDATA[MVP]]></category>
		<category><![CDATA[Presenter]]></category>
		<category><![CDATA[separation of concerns]]></category>
		<category><![CDATA[Unit Test]]></category>
		<category><![CDATA[View]]></category>

		<guid isPermaLink="false">http://www.gwttutorial.com/?p=353</guid>
		<description><![CDATA[GWT MVP Pattern There is a ton of hype about the Model, View and Presenter (or MVP for short) pattern on the GWT forums and tutorial sites.  Unfortunately, there is just as much confusion about the GWT MVP Pattern as there is discussion.  The trick to this pattern is realizing that there really is nothing [...]]]></description>
			<content:encoded><![CDATA[<h2><a href="http://www.gwttutorial.com/wp-content/uploads/2012/09/GWT-MVP-Pattern.jpg"><img class="alignleft size-medium wp-image-377" title="GWT MVP Pattern" src="http://www.gwttutorial.com/wp-content/uploads/2012/09/GWT-MVP-Pattern-300x261.jpg" alt="gwt development " width="300" height="261" /></a>GWT MVP Pattern</h2>
<p>There is a ton of hype about the Model, View and Presenter (or MVP for short) pattern on the GWT forums and tutorial sites.  Unfortunately, there is just as much confusion about the <a title="GWT MVP Pattern" href="https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces" target="_blank"><em>GWT MVP Pattern</em></a> as there is discussion.  The trick to this pattern is realizing that there really is nothing new about it, the pattern is a twist on some older patterns that you may be very familiar with.</p>
<h2>Advantages of the GWT MVP Pattern</h2>
<p>Before we get into the actual how-to of MVP, it is good to know why you actually should be using this pattern.  Just blindly doing something because it is the &#8220;new thing&#8221;, &#8220;everyone is doing it&#8221;, or &#8220;cool &gt; useful&#8221; is usually a bad idea.  Know why you want to use something before you use it.</p>
<h3>Decoupling</h3>
<p>The first advantage for MVP is to decouple the view and the logic.  We all know that it is a good idea to decouple responsibilities as much as possible and the view and control code is no exception.  The old adage &#8220;let a class do one thing only and do that thing well&#8221; is sage advice and the MVP pattern helps with that.  When done properly, you will have one class that is the view and one that is the logic that controls the view&#8217;s behavior.  Of course, the best way to do this is through the use of interfaces.  The view would typically communicate via a presenter interface and the presenter would control the view through a view interface.</p>
<h3>Unit Testing</h3>
<p>If you are coding through the interfaces from the Decoupling section, then you will find unit testing your presenters a breeze especially if you are using a dependency injection framework like <a title="GWT GIN and Dependency Injection" href="http://www.gwttutorial.com/gwt-gin/gwt-injection-with-gin" target="_blank">Gin and Guice</a>.  When you create the instance of the presenter for the unit test, you can inject a mock of the view quite easily and control its behavior from the setup of the test.  The best part of this is you don&#8217;t have to use <a title="Testing with GWTTestCase" href="https://developers.google.com/web-toolkit/doc/1.6/DevGuideTesting" target="_blank">GWTTestCase</a>.  This keeps you from needing to spin up a GWT container for every test which can be extremely time consuming.  Unit tests for presenters are just as fast as normal tests because they ARE normal tests.  There is never an excuse not to run them!</p>
<h3>Coding to Other Platforms</h3>
<p>One very cool feature, if you use the &#8220;correct version&#8221; of MVP, is that you can reuse your presenter logic on many other platforms for free.  Remember, you are writing actual Java code and there is no reason that you couldn&#8217;t drop it into a Swing or Android application.  Just rewrite the the view in whatever platform you are supporting, wire it to your presenter and ** POOF Magic ** you have a working application.</p>
<p>What do I mean by the &#8220;correct version&#8221;?  First, you need to code to interfaces because the presenter can&#8217;t be hard wired to the GWT version of your view.  Secondly, the view interface can&#8217;t expose any GWT specific widgets or interfaces.  For example, if your view interface has a method called getFirstNameHasText() and it returns the GWT version of the HasText interface, it won&#8217;t work on any other platforms.</p>
<h2>GWT MVP Pattern Code Example</h2>
<p>There are two main camps when it comes to using the MVP pattern.  The main difference seems to be the responsibility of presenter.  One side exposes interfaces for the presenter to register itself for change events from the widgets and the other delegates that responsibility to the view which in turn tells the presenter if something happens.  Personally, I am in the second camp because it looks cleaner and if you are going to be supporting multiple platforms you don&#8217;t need to write a bunch of wrapper classes to register to in order to expose the widgets.  I will show both versions of the <em>GWT MVP Pattern</em> and you can choose which one you like the best.</p>
<p>For this example, lets assume we have a form that we want to collect the user&#8217;s name.  This is of course a fairly trivial example, but when you do larger, more complex systems, it is really just a matter of copy and paste for each control on your form.  It doesn&#8217;t get more complex as you add more to the screen.</p>
<p></p><pre class="crayon-plain-tag">public class User {
	
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
}</pre><p></p>
<h3>GWT MVP Pattern implementation #1</h3>
<p>The first implementation is to completely decouple the view and presenter with interfaces and make them talk to each other through the interfaces (the &#8220;version&#8221; that I prefer) and not through registration of listeners.  The view and presenter interfaces would be something along the lines of the following:</p>
<p></p><pre class="crayon-plain-tag">public interface VersionOneView {

	public void setName(String name);
	public void setPresenter(VersionOnePresenter presenter);
	
}</pre><p></p>
<p></p><pre class="crayon-plain-tag">public interface VersionOnePresenter {

	public void handleNameChanged(String name);
	
}</pre><p></p>
<p>As you can see, this will allow each other to let the other one know that something has changed but not know anything about how the other is implemented.  You will also notice the setPresenter on the view interface.  This may or may not be there depending on how you are creating your classes.  If you are using a dependency injection framework, you probably won&#8217;t have these types of &#8220;handshake&#8221; methods which leads to cleaner looking code.</p>
<p>Now to the meatier pieces, the presenter and view.  First lets take a look at the implementation of the presenter:</p>
<p></p><pre class="crayon-plain-tag">public class VersionOnePresenterImpl implements VersionOnePresenter {
	
	private User bean;

	public VersionOnePresenterImpl(VersionOneView view, User bean) {
		// we need to keep a reference to update later
		this.bean = bean;
		
		// needed if you aren't using dependency injection
		view.setPresenter(this);
		
		// set the values into the view to be displayed
		view.setName(bean.getName());
	}

	@Override
	public void handleNameChanged(String name) {
		// the view is telling us the name changed so we need to save it
		bean.setName(name);
	}

}</pre><p></p>
<p>There are three main pieces to note in this code.  Line 10 is simply showing a bit of manual wiring that happens without dependency injection.  That way the view will have a reference to the presenter for later on.  Line 13 is an example of how the presenter takes data from the model and tells the view to display the information.  Remember, one of the presenter&#8217;s jobs is to be a bridge between the view and model.</p>
<p>Then on line 19 we have a situation that may not seem quite intuitive yet because we haven&#8217;t looked at the view implementation yet.  This is the method that will be called from the view when the name text box has changed values.  When the presenter is told about a change to the name value, it needs to save it into the model.</p>
<p>In the view, things get a little tricky if you aren&#8217;t used to any type of GUI programming.  I am also taking the liberty of assuming that the nameTextBox was somehow magically created and added to the UI.  There are several ways to do this such as programmatically doing it in the view constructor or using UIBinder.  How ever you choose to do it, don&#8217;t get hung up on this, it doesn&#8217;t matter to the pattern we are looking at.</p>
<p></p><pre class="crayon-plain-tag">public class VersionOneViewImpl implements VersionOneView {

	// assume this is created and added to the page
	private TextBox nameTextBox;
	private VersionOnePresenter presenter;
	
	public VersionOneViewImpl() {
		nameTextBox.addChangeHandler(new ChangeHandler() {
			@Override
			public void onChange(ChangeEvent event) {
				presenter.handleNameChanged(nameTextBox.getText());
			}
		});
	}

	@Override
	public void setName(String name) {
		nameTextBox.setText(name);
	}

	@Override
	public void setPresenter(VersionOnePresenter presenter) {
		this.presenter = presenter;
	}

}</pre><p></p>
<p>The first item to notice in the view is on line 8 and 11.  Line 8 is simply registering for a change notification and line 11 is telling the presenter that it needs to do something with this new value.  The view really doesn&#8217;t care about what the presenter does as long as it does something.</p>
<p>Line 18 is getting called from the constructor of the presenter.  When the presenter tells the view what the actual value is, it needs to turn around and set the value into the actual control.</p>
<p>That is really all there is to the version 1 of the <em>GWT MVP </em><em>Pattern</em> implementation.  It is pretty straight forward once you understand the few moving parts.</p>
<h3>GWT MVP Pattern implementation #2</h3>
<p>The second variation to the pattern is to have the presenter register itself to exposed interfaces and handle change events itself.  As in the last example, we will take a look at the interfaces before we get started with the real code.  Make note in this version that there doesn&#8217;t really need to be an interface for the Presenter because the view never is going to talk directly to it.</p>
<p></p><pre class="crayon-plain-tag">public interface VersionTwoView {

	public HasText getNameHasText();
	public HasChangeHandlers getNameHasChangeHandlers();
	
}</pre><p></p>
<p>Line 3 is the big change here.  It is returning a HasText along with a new naming convention for the method name.  The HasText is a GWT interface that simply allows you to interact with the instance as something that contains and displays text in an unknown way.  If you are going to stick with this version of implementation, it is a good idea to adopt the naming convention as well.  It is quite easy to tell what you are going to be dealing with just by looking at the name.  If there was a method called getSaveHasClickHandlers(), you could safely assume that you are probably working with a save button that you need to register a ClickHandler with.</p>
<p>Line 4 is how you will register the presenter to listen for changes to the name widget.  Then when the value changes, the listener will in turn update the model.</p>
<p></p><pre class="crayon-plain-tag">public class VersionTwoViewImpl implements VersionTwoView {
	
	// assume this is created and added to the page
	private TextBox nameTextBox;

	@Override
	public HasText getNameHasText() {
		return nameTextBox;
	}

	@Override
	public HasChangeHandlers getNameHasChangeHandlers() {
		return nameTextBox;
	}

}</pre><p></p>
<p>Notice in the implementation that both of the methods return the nameTextBox.  It just so happens that TextBox implements both the HasText and the HasChangeHandlers interfaces.  Interestingly, with this version of the <em>GWT MVP Pattern</em> the view becomes a bit more simple.  It is only responsible for laying out the widgets and providing access to them</p>
<p>The presenter is where the largest changes come into play.  Just like the last example, it is responsible for initially setting the values into the widget.  It just happens that this is accomplished differently.  The presenter is also required to register handlers for change events so the model can get updated.</p>
<p></p><pre class="crayon-plain-tag">public class VersionTwoPresenterImpl {

	public VersionTwoPresenterImpl(final VersionTwoView view, final User bean) {
		// first set the values that need to be displayed
		view.getNameHasText().setText(bean.getName());
		
		// register for change notifications
		view.getNameHasChangeHandlers().addChangeHandler(new ChangeHandler() {
			@Override
			public void onChange(ChangeEvent event) {
				bean.setName(view.getNameHasText().getText());
			}
		});
	}
	
}</pre><p></p>
<p>The presenter accomplishes its first responsibility on line 5.  It asks the view for the HasText and sets the value from the model into the view component.  This is fairly straight forward.  The second requirement of listening for changes has a bit more to it.  Line 8 and 11 is where the listening and updating is accomplished.  Line 8 asks the view for the HasChangehandlers and then registers a new ChangeHandler to take care of the changes.  When the value in the text box changes, line 11 will be called.  The presenter once again asks the view for the HasText, gets its value, and then sets it into the model.</p>
<h2>Wrap Up Discussion</h2>
<p>Both versions have merit and, to be honest, some of the decision comes down to personal style.  Some folks feel that one or the other looks more aesthetically pleasing to them.  In the end, the reason that I chose the first example over the second is because of unit testing.  There is far less that you need to actually mock out in the first version.  There are no HasText or HasChangeHandlers to mock, just the view interface (which is extremely easy if you are using <a title="Mockito - Simpler &amp; Better Mocking" href="http://code.google.com/p/mockito/" target="_blank">Mockito</a> or <a title="EasyMock Home" href="http://www.easymock.org/" target="_blank">EasyMock</a>).</p>
<p>No matter which version you use, the GWT MVP Pattern is definitely the right way to go.  Don&#8217;t get hung up on which version or all the nitty gritty details of all the arguments across the internet, just pick one and stick with it.  The important part is that you are doing it and using a great design!</p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/GOF' rel='tag' target='_blank'>GOF</a>, <a class='technorati-link' href='http://technorati.com/tag/gwt' rel='tag' target='_blank'>gwt</a>, <a class='technorati-link' href='http://technorati.com/tag/GWT+MVP+Pattern' rel='tag' target='_blank'>GWT MVP Pattern</a>, <a class='technorati-link' href='http://technorati.com/tag/Model' rel='tag' target='_blank'>Model</a>, <a class='technorati-link' href='http://technorati.com/tag/MVP' rel='tag' target='_blank'>MVP</a>, <a class='technorati-link' href='http://technorati.com/tag/Presenter' rel='tag' target='_blank'>Presenter</a>, <a class='technorati-link' href='http://technorati.com/tag/separation+of+concerns' rel='tag' target='_blank'>separation of concerns</a>, <a class='technorati-link' href='http://technorati.com/tag/Unit+Test' rel='tag' target='_blank'>Unit Test</a>, <a class='technorati-link' href='http://technorati.com/tag/View' rel='tag' target='_blank'>View</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.gwttutorial.com/gwt-development/gwt-mvp-pattern/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>GWT MVP, Activities and Places Confusion</title>
		<link>http://www.gwttutorial.com/gwt-development/gwt-mvp-activities-and-places-confusion</link>
		<comments>http://www.gwttutorial.com/gwt-development/gwt-mvp-activities-and-places-confusion#comments</comments>
		<pubDate>Wed, 15 Aug 2012 19:12:19 +0000</pubDate>
		<dc:creator>Jeff Richley</dc:creator>
				<category><![CDATA[GWT Development]]></category>
		<category><![CDATA[Activities and Places]]></category>
		<category><![CDATA[confusion]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[MVP]]></category>
		<category><![CDATA[separation of concerns]]></category>

		<guid isPermaLink="false">http://www.gwttutorial.com/?p=322</guid>
		<description><![CDATA[GWT MVP, Activities and Places Confusion As people start to dig into the real meat of GWT, they usually find themselves scratching their head about how to design their application.  All of the tutorials about GWT give good introduction applications to give a general idea of the concepts, but that is where they usually leave [...]]]></description>
			<content:encoded><![CDATA[<h2>GWT MVP, Activities and Places Confusion</h2>
<p><img class="alignright size-thumbnail wp-image-333" style="border-style: initial; border-color: initial;" title="confused" src="http://www.gwttutorial.com/wp-content/uploads/2012/08/confused-150x150.jpg" alt="gwt development " width="150" height="150" /></p>
<p>As people start to dig into the real meat of GWT, they usually find themselves scratching their head about how to design their application.  All of the tutorials about GWT give good introduction applications to give a general idea of the concepts, but that is where they usually leave off.  Most people begin their confusion with the differences between the <a title="MVP Tutorial" href="https://developers.google.com/web-toolkit/articles/mvp-architecture" target="_blank"><strong>MVP</strong></a> pattern and GWT&#8217;s framework called <a title="GWT Activities and Places" href="https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces" target="_blank"><strong>Activities and Places</strong></a>.</p>
<p>The confusion seems to grow and grow until the person finds themselves utterly frustrated and posting on forums, or even worse, giving up completely.  Don&#8217;t let this happen to you!  The trick to demystifying these two concepts is understanding that they have ABSOLUTELY NOTHING to do with each other.  You may see them mentioned in the same article online or in the same tutorial, but that just muddies the water.</p>
<p>Think of them as two separate design patterns.  (<em>Yeah, ok, Activities and Places is more of a framework, but just go with it.</em>)  Just like the Gang of Four patterns can be used together, <strong><a title="MVP Tutorial" href="https://developers.google.com/web-toolkit/articles/mvp-architecture" target="_blank">MVP</a> </strong>and <a title="GWT Activities and Places" href="https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces" target="_blank"><strong>Activities and Places</strong></a> can be used side by side.</p>
<p>So what are they?  Glad you asked!</p>
<h2>Model, View and Presenter</h2>
<div>The model, view, presenter pattern is really not much more than an extension to the old behavioral pattern called model, view and controller from a few years back.  The idea is that there is a class (presenter) that specializes in tying the data (model) with the presentation of the data (view).  The presenter is also responsible for logic and control of other items as well.  This concept is best thought of as separation of concerns for a well designed GUI application.&nbsp;</p>
<h2>Activities and Places</h2>
<div>GWT&#8217;s framework called <a title="GWT Activities and Places" href="https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces" target="_blank"><strong>Activies and Places</strong></a> is used for managing &#8220;bookmarkable pages&#8221; in a GWT application.  As you are well aware of, a GWT application is one single page with a whole slew of dynamic processing going on.  Historically, it was difficult to be able to bookmark a specific spot in your application and come back to it, that is what <a title="GWT Activities and Places" href="https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces" target="_blank"><strong>Activities and Places</strong></a> for you.  As you navigate through your application, you wi<br />
Another side benefit to using Activities and Places is history management.  Due to the fact that Activities and Places work directly off of the browser&#8217;s URL, the browser&#8217;s back and forward button is auto-magically now part of your GWT application.  When the browser back button is clicked, the URL is changed which in turn makes changes to the state of your activities inside your application.ll see the URL of your application constantly changing.  These individual &#8220;bookmarkable links&#8221; let you jump into your application and pick right back up where you left off before.  The great part is that you don&#8217;t have to worry about coding the link part yourself, that is the responsibility of the framework.&nbsp;</p>
<h2>Two peas in a pod</h2>
<p>I think the biggest source of confusion is that these two patterns/frameworks work very well in conjunction with each other.  Its kind of like chocolate and peanut butter, put them together and you have yummy goodness but it is hard to tell them apart once they are mixed.</p>
<p>Just remember that MVP is used for separation of concerns and Activies and Places is used for URL and history management.</p>
<p><strong>Here is a great talk about the major concepts of GWT (who doesn&#8217;t love David Chandler?)</strong></p>
<p><iframe title="YouTube video player" class="youtube-player" type="text/html" width="425" height="344" src="http://www.youtube.com/embed/0F5zc1UAt2Y" frameborder="0" allowFullScreen="true"> </iframe></p>
</div>
</div>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Activities+and+Places' rel='tag' target='_blank'>Activities and Places</a>, <a class='technorati-link' href='http://technorati.com/tag/confusion' rel='tag' target='_blank'>confusion</a>, <a class='technorati-link' href='http://technorati.com/tag/google' rel='tag' target='_blank'>google</a>, <a class='technorati-link' href='http://technorati.com/tag/gwt' rel='tag' target='_blank'>gwt</a>, <a class='technorati-link' href='http://technorati.com/tag/MVP' rel='tag' target='_blank'>MVP</a>, <a class='technorati-link' href='http://technorati.com/tag/separation+of+concerns' rel='tag' target='_blank'>separation of concerns</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.gwttutorial.com/gwt-development/gwt-mvp-activities-and-places-confusion/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google&#8217;s Developer Education Programs</title>
		<link>http://www.gwttutorial.com/gwt-news/googles-developer-education-programs</link>
		<comments>http://www.gwttutorial.com/gwt-news/googles-developer-education-programs#comments</comments>
		<pubDate>Tue, 17 Jul 2012 15:19:49 +0000</pubDate>
		<dc:creator>Jeff Richley</dc:creator>
				<category><![CDATA[GWT News]]></category>

		<guid isPermaLink="false">http://www.gwttutorial.com/?p=296</guid>
		<description><![CDATA[I never cease to be amazed by Google and everything they keep doing for the general public, but wow, now the development comunity is really starting to feel the Google love too.  Google has launched a new education program called Google Developers Academy.  There is tons of tutorials and code walk throughs on this site [...]]]></description>
			<content:encoded><![CDATA[<p>I never cease to be amazed by Google and everything they keep doing for the general public, but wow, now the development comunity is really starting to feel the Google love too.  Google has launched a new education program called <a title="Google Developers Academy" href="https://developers.google.com/academy/" target="_blank">Google Developers Academy</a>.  There is tons of tutorials and code walk throughs on this site to help you with just about any issue that you can imagine.  Some of the topics they cover are Android, Google Drive, and Google App Engine.  If you are confused about anything, this is the place for you.</p>
<p>Yet another great resource to get warm and fuzzies from is <a title="Google Developers Live" href="https://developers.google.com/live/" target="_blank">Google Developers Live</a>.  Google has put together a place for you to get great information directly from Googlers and other developers.  Yes you read that right, people are actually online to help you out with your questions and issues.  When I saw this, I thought it was a fabulous way for Google to use their Google Hangouts.  What company have you ever seen that is willing to dedicate their staff&#8217;s time to help you out for free?</p>
<p>I&#8217;ve heard people people debating if they should use GWT or even just rely on Google technologies, I think the answer is clear.  They are heavily invested in your future and success.  You can&#8217;t go wrong with Google!</p>
<p>&nbsp;</p>

<!-- start wp-tags-to-technorati 1.02 -->

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.gwttutorial.com/gwt-news/googles-developer-education-programs/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GWT is Going Open Source</title>
		<link>http://www.gwttutorial.com/gwt-news/gwt-is-going-open-source</link>
		<comments>http://www.gwttutorial.com/gwt-news/gwt-is-going-open-source#comments</comments>
		<pubDate>Fri, 13 Jul 2012 13:31:31 +0000</pubDate>
		<dc:creator>Jeff Richley</dc:creator>
				<category><![CDATA[GWT News]]></category>

		<guid isPermaLink="false">http://www.gwttutorial.com/?p=289</guid>
		<description><![CDATA[GWT has been picking up steam over the last several years.  Every time Google releases an update, there is new and innovative changes including compiler speed, profiling tools, HTML 5 support, and WYSIWYG editors.  They have gone and done it again!&#160; Ray Cromwell, the technical lead, announced at Google I/O that once GWT 2.5 is [...]]]></description>
			<content:encoded><![CDATA[<div>GWT has been picking up steam over the last several years.  Every time Google releases an update, there is new and innovative changes including compiler speed, profiling tools, HTML 5 support, and WYSIWYG editors.  They have gone and done it again!&nbsp;</p>
<p>Ray Cromwell, the technical lead, announced at Google I/O that once GWT 2.5 is released, the Google Web Toolkit is going to be released as an open source project.  Google is going to relinquish control to a committee which will decide the direction of this tool.Cromwell is going to be the committee chairperson along with folks from some well known companies such as Sencha, Red Hat, and Vaadin.  Other individuals include well known advocates such as Daniel Kurka, Christian Goudreau, and Thomas Broyer.</p>
<p>What is this going to do for the GWT community?  Great question.  Apparently, the group has already decided to change code repositories from Subversion to Git and to change the development effort slightly by creating two major code branches: a bleeding edge and more mature beta branch.  I for one am excited about being able to try out the latest and greatest they have to offer!</p>
<p>When is this going to happen?  From what Cromwell said, the major move is happening after GWT 2.5 comes out which is rumored to be around the first of August.</p>
<p>Are you concerned about this radical move from Google?  Many people are, but I would remind you back when IBM did the same thing with their Eclipse product.  It was a good tool before they opened it up, but once they did it became the leading tool in the market place.</p>
<p>What do you think about this move?  I’d love to hear your comments.</p>
</div>

<!-- start wp-tags-to-technorati 1.02 -->

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.gwttutorial.com/gwt-news/gwt-is-going-open-source/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Global Exception Handling in GWT</title>
		<link>http://www.gwttutorial.com/gwt-development/global-exception-handling-in-gwt</link>
		<comments>http://www.gwttutorial.com/gwt-development/global-exception-handling-in-gwt#comments</comments>
		<pubDate>Tue, 15 May 2012 19:57:43 +0000</pubDate>
		<dc:creator>Jeff Richley</dc:creator>
				<category><![CDATA[GWT Development]]></category>

		<guid isPermaLink="false">http://www.gwttutorial.com/?p=257</guid>
		<description><![CDATA[Ghosts in the Machine &#8211; When Exceptions Happen There are times when your GWT application will simply do wild and crazy things and you have no idea why they are happening.  Or even worse, it will not do things that it is supposed to!  You can spend hours upon hours of pulling out your hair [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gwttutorial.com/wp-content/uploads/2012/05/global-exception-handling-in-gwt.jpg"><img class="alignleft size-medium wp-image-260" title="Global Exception Handling In GWT" src="http://www.gwttutorial.com/wp-content/uploads/2012/05/global-exception-handling-in-gwt-300x199.jpg" alt="gwt development " width="300" height="199" /></a></p>
<h2>Ghosts in the Machine &#8211; When Exceptions Happen</h2>
<p>There are times when your GWT application will simply do wild and crazy things and you have no idea why they are happening.  Or even worse, it will not do things that it is supposed to!  You can spend hours upon hours of pulling out your hair trying to trace down the exact area that is failing without any luck.  There is also the dreaded &#8220;It works in dev mode, but not when it is running in web mode!&#8221;  Just thinking about that makes me cringe.  Many times it comes down to knowing the tricks for <strong>exception handling in gwt</strong>.<span id="more-257"></span></p>
<p>If you work on any production grade application written in GWT, you will come across something like this.  It is almost inevitable, but if you are armed with just a few simple tricks, you can save hours if not days of frustration and rewriting of code.</p>
<p>For me, I first encountered this brain buster when I was trying to add a new library into my project.  I thought I had followed the instructions to the &#8220;T&#8221;, and I had&#8230;almost.   I had done the obligatory &#8220;inheriting the external module&#8221; in my project.gwt.xml file (this tells GWT that there is an external source of code to go look for) and had even properly initialized this new library.  Even though these had been correctly done, I still wasn&#8217;t getting the correct behavior.  After what seemed like a lifetime of poking around inside the new library&#8217;s code (and almost ditching it), I realized that it was my own fault because I was not using one of the classes quite right.</p>
<p>What was actually happening?  Down in the bowls of this new library, there was a RuntimeException being thrown due to my incorrect usage.  At first glance this may seem like I should have been able to catch this rather easily, but here is the rest of the story.  In the method call, there was a command scheduled to run at a later time and during that command&#8217;s execution the Exception was being thrown.  I couldn&#8217;t just wrap my method call with a try-catch block and log a stack trace because it was running at some later, undefined time.  So what&#8217;s the answer?  How can you track this down the easy way?</p>
<h2>Global Exception Handling</h2>
<p>The answer is to register a <strong>global exception handler</strong> in your entry point class.  Ok, ok, technically it doesn&#8217;t have to be in the EntryPoint class, but that is a good place to put it.</p>
<p>The basic concept is that if anything happens to go wrong somewhere at sometime during the execution of your application, and there are no handlers to take care of Exceptions that pop up, this particular piece of code will get called and handle it.  Now theoretically, there isn&#8217;t really much you can do typically at a global scale to handle an arbitrary Exception, so this is usually a good place to put some sort of logging and message the user that something has gone wrong.</p>
<p>No matter what your production code will eventually do, this is a great place to put some debug code to give you a glimpse into your development woes.  You can find some other good ideas for this at the <a title="Other GWT Developer Articles" href="https://developers.google.com/web-toolkit/doc/latest/DevGuide" target="_blank">GWT Developer site</a>.</p>
<h2>Registering a Global Exception Handler</h2>
<p>When I discovered this little trick, I couldn&#8217;t believe just how easy it is to register the handler.  It felt like it was just a tad bit too easy and I had to be missing something.  It is so simple in fact that when I make new projects, one of the first things I do right after I cut the generated code is to add a <strong>Global Exception Handler</strong> right at the beginning of my EntryPoint class.  Here is my typical &#8220;debugger handler&#8221; that I add to save hours of grief and frustration.</p>
<p>&nbsp;</p><pre class="crayon-plain-tag">GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
    @Override
    public void onUncaughtException(Throwable e) {
        Window.alert(&quot;Uncaught Exception: &quot; + e.getMessage());
        e.printStackTrace();
    }
});</pre><p>Notice on line 4 and 5, I have put two types of logging.  Line 4 will actually display a browser Alert box to tell me what is going on and line 5 will print out a stack trace.  I may switch back and forth between these from time to time because I may not want to see the Alert box.  Keep in mind though, there is no console when you are running in web mode and that Alert box is the only indication that something went wrong.</p>
<p>Keep this little trick in your back pocket for the next time your application is behaving in odd ways and you will save tons of time and frustration.</p>
<p>&nbsp;</p>
<p>External Sources</p>
<p><a title="setUncaughtExceptionHandler JavaDoc" href="http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/core/client/GWT.html#setUncaughtExceptionHandler(com.google.gwt.core.client.GWT.UncaughtExceptionHandler)" target="_blank">setUncaughtExceptionHandler JavaDoc</a></p>
<p><a title="Other GWT Developer Articles" href="https://developers.google.com/web-toolkit/doc/latest/DevGuide" target="_blank">Other GWT Developer Articles</a></p>
<p><span style="text-decoration: underline;"><em>Google I/O - Best Practices for Architecting GWT App</em></span></p>
<p><iframe title="YouTube video player" class="youtube-player" type="text/html" width="425" height="344" src="http://www.youtube.com/embed/PDuhR18-EdM" frameborder="0" allowFullScreen="true"> </iframe></p>

<!-- start wp-tags-to-technorati 1.02 -->

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.gwttutorial.com/gwt-development/global-exception-handling-in-gwt/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hiring GWT Jobs &#8211; 4 Developers</title>
		<link>http://www.gwttutorial.com/gwt-job/hiring-gwt-jobs-4-developers</link>
		<comments>http://www.gwttutorial.com/gwt-job/hiring-gwt-jobs-4-developers#comments</comments>
		<pubDate>Thu, 26 Apr 2012 19:05:51 +0000</pubDate>
		<dc:creator>Jeff Richley</dc:creator>
				<category><![CDATA[GWT Job]]></category>

		<guid isPermaLink="false">http://www.gwttutorial.com/?p=239</guid>
		<description><![CDATA[4 GWT Jobs Available I wanted to put a word out to everyone that may be interested in working with GWT and other high end technologies such as the Casandra NoSQL database. The job is focused on high end scalable systems targeted for the tech generation of the Navy and Marine Corp.  We use GWT for [...]]]></description>
			<content:encoded><![CDATA[<h2><a href="http://www.gwttutorial.com/wp-content/uploads/2012/04/GWT-job.png"><img class="alignnone size-full wp-image-240" title="gwt-job" src="http://www.gwttutorial.com/wp-content/uploads/2012/04/GWT-job.png" alt="gwt job " width="210" height="200" /></a>4 GWT Jobs Available</h2>
<p>I wanted to put a word out to everyone that may be interested in working with GWT and other high end technologies such as the Casandra NoSQL database.</p>
<p>The job is focused on high end scalable systems targeted for the tech generation of the Navy and Marine Corp.  We use GWT for the front end technologies and Casandra and Oracle for the data store.  The team is a very tight knit group that is looking to add four additional people that are eager to learn and grow in their profession.  The group is fairly high paced, but certainly know how to have a good time.</p>
<p>They provide full benefits, medical, dental, and eye.  It is is for two years with the option to extend longer, possibly permanent.  The development group is located in Norfolk, VA.  If you&#8217;d like to get more information, please feel free to send me a personal email, jeffrichley@gmail.com or even call me, 757-576-9634.</p>

<!-- start wp-tags-to-technorati 1.02 -->

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.gwttutorial.com/gwt-job/hiring-gwt-jobs-4-developers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GWT Upload in 3 Easy Steps</title>
		<link>http://www.gwttutorial.com/gwt-development/gwt-upload-in-3-easy-steps</link>
		<comments>http://www.gwttutorial.com/gwt-development/gwt-upload-in-3-easy-steps#comments</comments>
		<pubDate>Fri, 13 Apr 2012 02:16:15 +0000</pubDate>
		<dc:creator>Jeff Richley</dc:creator>
				<category><![CDATA[GWT Development]]></category>

		<guid isPermaLink="false">http://www.gwttutorial.com/?p=199</guid>
		<description><![CDATA[3 steps for uploading files in GWT There are several very fancy and easy to use GWT Upload libraries that you can use in your applications but sometimes you just need a very simple interface to add an upload functionality to your application.  While the GWT client side of the upload process is the easiest [...]]]></description>
			<content:encoded><![CDATA[<h2>3 steps for uploading files in GWT</h2>
<p><a href="http://www.gwttutorial.com/wp-content/uploads/2012/04/GWT-Upload.jpg"><img class="alignleft size-thumbnail wp-image-204" title="GWT Upload" src="http://www.gwttutorial.com/wp-content/uploads/2012/04/GWT-Upload-150x150.jpg" alt="gwt development " width="150" height="150" /></a>There are several very fancy and easy to use <em>GWT Upload </em>libraries that you can use in your applications but sometimes you just need a very simple interface to add an upload functionality to your application.  While the GWT client side of the upload process is the easiest part, many people miss the little tweak that you need to use.</p>
<p>If you want to use one of the fancier upload libraries for cool effects like upload status, I would recommend using <a title="GWT-Upload" href="http://code.google.com/p/gwt-upload/" target="_blank">GWT-Upload</a>, <a title="GwtUpload" href="http://code.google.com/p/gwtupload/" target="_blank">GwtUpload</a>, or <a title="Upload4Gwt" href="http://code.google.com/p/upload4gwt/" target="_blank">Upload4Gwt</a>.</p>
<p>In order to add this to your page, follow these three easy steps&#8230;<br />
<span id="more-199"></span></p>
<h3>Step 1: Create a file upload servlet</h3>
<p>There are tons of examples across the internet showing how to do this.  The easiest way is to use the <a title="Apache Commons FileUpload" href="http://commons.apache.org/fileupload/" target="_blank">Apache Commons FileUpload</a> library.  An example of a fairly trivial use of this library looks like this:</p><pre class="crayon-plain-tag">// Example from Apache Commons FileUpload
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();

// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);

// Parse the request
List /* FileItem */ items = upload.parseRequest(request);</pre><p></p>
<h3> Step 2: Modify web.xml</h3>
<p>If you are writing a servlet, it goes without saying that you need to add an entry into the web.xml file.</p><pre class="crayon-plain-tag">&amp;lt;servlet&amp;gt;
    &amp;lt;servlet-name&amp;gt;FileUploaderServlet&amp;lt;/servlet-name&amp;gt;
    &amp;lt;servlet-class&amp;gt;com.myapp.server.FileUploadServlet&amp;lt;/servlet-class&amp;gt;
&amp;lt;/servlet&amp;gt;
&amp;lt;servlet-mapping&amp;gt;
  &amp;lt;servlet-name&amp;gt;FileUploaderServlet&amp;lt;/servlet-name&amp;gt;
  &amp;lt;url-pattern&amp;gt;/myapp/fileupload&amp;lt;/url-pattern&amp;gt;
&amp;lt;/servlet-mapping&amp;gt;</pre><p>The &lt;servlet&gt; tag tells the web server that you have a class and you want it known by this servlet name.  Then in the &lt;servlet-mapping&gt;, you tell it that the class known by this name, should be invoked when the given URL pattern is requested.</p>
<p>At this point the server is done and all you need is to make the client side of the task</p>
<h3>Step 3: GWT Upload Form</h3>
<p>Create a <a title="GWT FormPanel" href="http://google-web-toolkit.googlecode.com/svn/javadoc/2.4/com/google/gwt/user/client/ui/FormPanel.html" target="_blank">FormPanel</a> and add it to your page. The most important part of this code is the <em>FormPanel.ENCODING_MULTIPART</em> and <em>FormPanel.METHOD_POST</em>.</p><pre class="crayon-plain-tag">// Used from FormPanel's Javadoc
// Create a FormPanel and point it at a service.
final FormPanel form = new FormPanel();
form.setAction(&quot;/myapp/fileupload&quot;);

// Because we're going to add a FileUpload widget, we'll need to set the
// form to use the POST method, and multipart MIME encoding.
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);

// Create a FileUpload widget.
FileUpload upload = new FileUpload();
upload.setName(&quot;uploadFormElement&quot;);
panel.add(upload);</pre><p></p>
<h3> Conclusion</h3>
<p>As you can see, it is simple to an upload functionality to your app.  Now if you do want to add more flash to your look and feel (and who doesn&#8217;t like flashy stuff), I would highly recommend using the libraries I suggested above, <a title="GWT-Upload" href="http://code.google.com/p/gwt-upload/" target="_blank">GWT-Upload</a>, <a title="GwtUpload" href="http://code.google.com/p/gwtupload/" target="_blank">GwtUpload</a>, or <a title="Upload4Gwt" href="http://code.google.com/p/upload4gwt/" target="_blank">Upload4Gwt</a>.  They do a fabulous job.  Here is an example of what Upload4Gwt looks like.</p>
<p>&nbsp;</p>
<p><center><a href="http://www.gwttutorial.com/wp-content/uploads/2012/04/Upload4GWT.png"><img class="alignnone size-medium wp-image-225" title="Upload4GWT Look and Feel" src="http://www.gwttutorial.com/wp-content/uploads/2012/04/Upload4GWT-300x214.png" alt="gwt development " width="300" height="214" /></a></center><br />
&nbsp;</p>

<!-- start wp-tags-to-technorati 1.02 -->

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.gwttutorial.com/gwt-development/gwt-upload-in-3-easy-steps/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GWT GIN and Dependency Injection</title>
		<link>http://www.gwttutorial.com/gwt-gin/gwt-injection-with-gin</link>
		<comments>http://www.gwttutorial.com/gwt-gin/gwt-injection-with-gin#comments</comments>
		<pubDate>Mon, 09 Apr 2012 13:50:54 +0000</pubDate>
		<dc:creator>Jeff Richley</dc:creator>
				<category><![CDATA[GWT GIN]]></category>
		<category><![CDATA[annotations]]></category>
		<category><![CDATA[deferred binding]]></category>
		<category><![CDATA[dependencies]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[factory]]></category>
		<category><![CDATA[factory interface]]></category>
		<category><![CDATA[gin]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google web]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[GWT Tutorial]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[junit test]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[reflection]]></category>
		<category><![CDATA[unit tests]]></category>
		<category><![CDATA[web toolkit]]></category>

		<guid isPermaLink="false">http://www.gwttutorial.com/?p=129</guid>
		<description><![CDATA[&#160; History and Theory of GIN Several years ago, the Google Brainiacs delivered a dependency injection framework called Guice. The idea behind Guice is to let the framework create all of your dependencies and you simply tell it what types of objects you would like to have to do your job. The Guice system will [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_147" class="wp-caption alignleft" style="width: 310px"><a href="http://amzn.to/HB95GI"><img class="size-full wp-image-147" title="google-guice-book" src="http://www.gwttutorial.com/wp-content/uploads/2012/04/google-guice-book.jpg" alt="gwt gin " width="300" height="300" /></a><p class="wp-caption-text">The best book on the market for learning Google Guice</p></div>
<p>&nbsp;</p>
<h1>History and Theory of GIN</h1>
<p>Several years ago, the Google Brainiacs delivered a dependency injection framework called Guice. The idea behind Guice is to let the framework create all of your dependencies and you simply tell it what types of objects you would like to have to do your job. The <em>Guice</em> system will determine the correct implementation classes for your requested interfaces and give them to you when appropriate.</p>
<p>This works extremely well in production mode, but it actually gives other benefits. This way of development helps you to design your software in a much more decoupled and modular way. You begin to lean on interfaces instead of concrete classes which is usually a very good thing. Because you are dependent on interfaces, your code becomes much easier to test.</p>
<p>Now fast forward a bit and you find yourself in a development group writing large systems with the Google Web Toolkit. You have read all about how Guice makes life easier and you are struggling to write unit tests for your GWT based code. You think to yourself, &#8220;Geez, wouldn&#8217;t it be nice if I could just use Guice?&#8221; Now you can do just that, <em>GWT GIN</em> (GWT INjection) brings automated dependency injection into the client side of development. It is based on Guice and uses the same annotations for its dependency injection.<span id="more-129"></span></p>
<h1>A GIN Example</h1>
<h2>Step 1: Setting up GWT GIN</h2>
<p>Along with adding the GIN jars to your classpath, you will need to inherit the module into your GWT application. The way to do this is add one &#8220;inherits line&#8221; into your myproject.gwt.xml file.</p><pre class="crayon-plain-tag">&amp;lt;module&amp;gt;
    &amp;lt;inherits name=&quot;com.google.gwt.inject.Inject&quot;/&amp;gt;
    &amp;lt;!-- Other module definition items --&amp;gt;
&amp;lt;/module&amp;gt;</pre><p></p>
<h2>Step 2: The GIN Ginjector</h2>
<p>The second step involves bridging the gap between the Guice and GIN worlds. Guice heavily relies on Java&#8217;s reflection libraries but this functionality is not available to GWT applications. You have to remember after all, your GWT applications are not running as Java apps, they are actually JavaScript running in a browser.</p>
<p>The way you bridge this gap is to create a Ginjector for your project. This is just an interface, no actual code behind it. If you have dabbled in GWT&#8217;s deferred binding system, you will understand that at compile time a good deal of code is generated for you and is statically available at runtime. That is exactly how GIN gets around the &#8220;no Java reflection&#8221; limitations. Your Ginjector interface will have code generated behind the scenes at compile time.</p><pre class="crayon-plain-tag">@GinModules(MyGinModule.class)
public interface MyGinjector extends Ginjector {
    public A getMyAObject();
}</pre><p>Notice the extension of Ginjector. This gives the compiler the hint that code needs to be generated under the covers. The @GinModules is also the final tie to the Guice portion of the work which is discussed in the next step.</p>
<p>Many developers get confused as to what to put in this interface. Think of the interface as a &#8220;top level factory.&#8221; The only things you should have this generate for you is what is needed at your very top level, in your EntryPoint class. For example, lets say you have three classes A, B, and C. If class B relies on C, A relies on B, and your entry point needs A, then your Ginjector interface would only have a method to create an instance of A. Remember, GIN is a dependency injection framework and you should let it take care of when to create B and C.</p>
<h2>Step 3: Making a GinModule</h2>
<p>Now that you have your Ginjector defined, you need to declare all of your bindings for your module. The example given here is a fairly trivial one, but you certainly can get the picture. The Guice side of the fence gives far more options to play with than is shown here. The @GinModules annotation from Step 2 ties the Ginjector and your GinModule together.</p><pre class="crayon-plain-tag">public class MyGinModule extends AbstractGinModule {
	protected void configure() {
		bind(A.class);
		bind(B.class);
		bind(C.class);
	}
}</pre><p>This configure method tells Gin and Guice that there are classes A, B, and C that need to be wired together. The actual class definitions tell Gin and Guice exactly how to wire them together. Take note of the @Inject annotations.</p><pre class="crayon-plain-tag">public class A {
	private B b;
	@Inject
	public A(B b) {
		this.b = b;
	}
}</pre><p></p><pre class="crayon-plain-tag">public class B {
	private C c;
	@Inject
	public B(C c) {
		this.c = c;
	}
}</pre><p></p><pre class="crayon-plain-tag">public class C {
}</pre><p></p>
<h2>Step 4: Invoking GIN</h2>
<p>The last bit is actually asking Gin for an instance of your object graph. If you have wired everything together properly, it should just magically work (don&#8217;t you just love it when the magical elves come from fairy land).</p><pre class="crayon-plain-tag">public class Myproject implements EntryPoint {
	public void onModuleLoad() {
		MyGinjector injector = GWT.create(MyGinjector.class);
		A a = injector.getMyAObject();
	}
}</pre><p>In a nut shell, what this code is doing is asking the GWT compiler to create all of the underlying code. This is accomplished by the deferred binding system with the GWT.create(MyGinjector.class). All of the declared interfaces get an actual bit of backing code during this process. Then it is simply asking the injector for the desired class.</p>
<p>As was stated before, this is a trivial example but you can certainly see the cookie cutter process that you would use to create a far more complex application wiring. If you want to really get the full bang for the buck, you would design your classes behind interfaces. This would allow you to mock your interactions in your JUnit tests. Even if you aren&#8217;t writing unit tests (shame, shame!!), it will help with your system design and separation of concerns.</p>
<h3>Other good resources for GWT GIN</h3>
<ul>
<li><a title="Official GWT GIN Site" href="http://code.google.com/p/google-gin/" target="_blank">Official GWT GIN Site</a></li>
<li><a title="Dependency Injection" href="http://en.wikipedia.org/wiki/Dependency_injection" target="_blank">Dependency Injection</a></li>
<li><a title="Official Google Guice Site" href="http://code.google.com/p/google-guice/" target="_blank">Official Google Guice Site</a></li>
</ul>
<h3> Google IO video using GWT GIN as a best practice</h3>
<p><iframe title="YouTube video player" class="youtube-player" type="text/html" width="425" height="344" src="http://www.youtube.com/embed/imiquTOLl64" frameborder="0" allowFullScreen="true"> </iframe></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/annotations' rel='tag' target='_blank'>annotations</a>, <a class='technorati-link' href='http://technorati.com/tag/deferred+binding' rel='tag' target='_blank'>deferred binding</a>, <a class='technorati-link' href='http://technorati.com/tag/dependencies' rel='tag' target='_blank'>dependencies</a>, <a class='technorati-link' href='http://technorati.com/tag/dependency+injection' rel='tag' target='_blank'>dependency injection</a>, <a class='technorati-link' href='http://technorati.com/tag/example' rel='tag' target='_blank'>example</a>, <a class='technorati-link' href='http://technorati.com/tag/factory' rel='tag' target='_blank'>factory</a>, <a class='technorati-link' href='http://technorati.com/tag/factory+interface' rel='tag' target='_blank'>factory interface</a>, <a class='technorati-link' href='http://technorati.com/tag/gin' rel='tag' target='_blank'>gin</a>, <a class='technorati-link' href='http://technorati.com/tag/google' rel='tag' target='_blank'>google</a>, <a class='technorati-link' href='http://technorati.com/tag/google+web' rel='tag' target='_blank'>google web</a>, <a class='technorati-link' href='http://technorati.com/tag/gwt' rel='tag' target='_blank'>gwt</a>, <a class='technorati-link' href='http://technorati.com/tag/GWT+Tutorial' rel='tag' target='_blank'>GWT Tutorial</a>, <a class='technorati-link' href='http://technorati.com/tag/Java' rel='tag' target='_blank'>Java</a>, <a class='technorati-link' href='http://technorati.com/tag/junit+test' rel='tag' target='_blank'>junit test</a>, <a class='technorati-link' href='http://technorati.com/tag/plugin' rel='tag' target='_blank'>plugin</a>, <a class='technorati-link' href='http://technorati.com/tag/reflection' rel='tag' target='_blank'>reflection</a>, <a class='technorati-link' href='http://technorati.com/tag/unit+tests' rel='tag' target='_blank'>unit tests</a>, <a class='technorati-link' href='http://technorati.com/tag/web+toolkit' rel='tag' target='_blank'>web toolkit</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.gwttutorial.com/gwt-gin/gwt-injection-with-gin/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using GWT Autobeans in JUnit Tests</title>
		<link>http://www.gwttutorial.com/gwt-autobeans/using-gwt-autobeans-in-junit-tests</link>
		<comments>http://www.gwttutorial.com/gwt-autobeans/using-gwt-autobeans-in-junit-tests#comments</comments>
		<pubDate>Tue, 03 Apr 2012 01:11:20 +0000</pubDate>
		<dc:creator>Jeff Richley</dc:creator>
				<category><![CDATA[GWT AutoBeans]]></category>
		<category><![CDATA[AutoBeans]]></category>
		<category><![CDATA[entity beans]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[factory]]></category>
		<category><![CDATA[factory interface]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[GWT Tutorial]]></category>
		<category><![CDATA[junit test]]></category>
		<category><![CDATA[model factory]]></category>

		<guid isPermaLink="false">http://www.gwttutorial.com/?p=120</guid>
		<description><![CDATA[GWT AutoBeans Where GWT AutoBeans Started GWT has created an awesome framework called AutoBeans. It was originally created to be part of the backing to the GWT RequestFactory change management. The basics is that given an interface that extends ValueProxy which represents a bean (using the typical getters and setters), AutoBeans does the actual creation [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_125" class="wp-caption alignleft" style="width: 310px"><a href="http://amzn.to/HgoITK"><img class="size-medium wp-image-125" title="gwt-autobeans" src="http://www.gwttutorial.com/wp-content/uploads/2012/04/gwt-autobeans-300x201.jpg" alt="gwt autobeans " width="300" height="201" /></a><p class="wp-caption-text">Using GWT AutoBeans in JUnit Test Cases</p></div>
<h1>GWT AutoBeans</h1>
<h2>Where GWT AutoBeans Started</h2>
<p>GWT has created an awesome framework called AutoBeans. It was originally created to be part of the backing to the GWT RequestFactory change management. The basics is that given an interface that extends ValueProxy which represents a bean (using the typical getters and setters), AutoBeans does the actual creation and managing of that bean.</p>
<p>The details aren&#8217;t really that important, just push the I believe button if you are using GWT&#8217;s Request Factory. AutoBeans is used to bridge the gap between the server side Entity beans and the GWT front end&#8217;s Data Transfer Objects. The problem that is introduced when using AutoBeans is using the interfaces in your JUnit Tests.</p>
<p>The Google Wizards actually made AutoBeans so that it can be used in GWT Applications as well as out of them, such as desktop and server apps. Due to this feature, you can also use them in your JUnit tests. Here is an example on how to do just that.<span id="more-120"></span></p>
<h2>GWT AutoBeans JUnit Example</h2>
<p>If you already are using RequestFactory, you probably already have your bean interfaces that are something like:</p><pre class="crayon-plain-tag">public interface MyBeanProxy extends ValueProxy {
	String getName();
	void setName(String name);
}</pre><p>In order to actually create your AutoBeans bean, you will need a factory interface:</p><pre class="crayon-plain-tag">package public interface BeanFactory extends AutoBeanFactory {
	AutoBean&amp;lt;MyBeanProxy&amp;gt; createMyBean();
}</pre><p>Once the interface and the factory are in place, you can now use them in your tests:</p><pre class="crayon-plain-tag">@Test
public void shouldHaveABeanImplementation() {
    BeanFactory factory = AutoBeanFactorySource.create(BeanFactory.class);
    model = factory.createMyBean().as();

    model.setName(&quot;GWTTutorial.com&quot;);

    // put your assertions here
}</pre><p>There you have it, that is all you need to do to stub out your GWT AutoBeans interfaces in your JUnit Test Cases.</p>
<p>Happy Coding!</p>
<h3>Other Resources for GWT AutoBeans</h3>
<ul>
<li><a title="Official GWT AutoBeans Site" href="http://code.google.com/p/google-web-toolkit/wiki/AutoBean" target="_blank">Official GWT AutoBeans Site</a></li>
<li><a title="GWT JavaScript Overlay Objects" href="https://developers.google.com/web-toolkit/doc/2.3/DevGuideCodingBasicsOverlay" target="_blank">GWT JavaScript Overlay Objects</a></li>
<li><a title="GWT RequestFactory" href="https://developers.google.com/web-toolkit/doc/2.3/DevGuideRequestFactory" target="_blank">GWT RequestFactory</a></li>
</ul>
<h3>Google IO Video Using GWT AutoBeans</h3>
<p><iframe title="YouTube video player" class="youtube-player" type="text/html" width="425" height="344" src="http://www.youtube.com/embed/imiquTOLl64" frameborder="0" allowFullScreen="true"> </iframe></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/AutoBeans' rel='tag' target='_blank'>AutoBeans</a>, <a class='technorati-link' href='http://technorati.com/tag/entity+beans' rel='tag' target='_blank'>entity beans</a>, <a class='technorati-link' href='http://technorati.com/tag/example' rel='tag' target='_blank'>example</a>, <a class='technorati-link' href='http://technorati.com/tag/factory' rel='tag' target='_blank'>factory</a>, <a class='technorati-link' href='http://technorati.com/tag/factory+interface' rel='tag' target='_blank'>factory interface</a>, <a class='technorati-link' href='http://technorati.com/tag/google' rel='tag' target='_blank'>google</a>, <a class='technorati-link' href='http://technorati.com/tag/gwt' rel='tag' target='_blank'>gwt</a>, <a class='technorati-link' href='http://technorati.com/tag/GWT+Tutorial' rel='tag' target='_blank'>GWT Tutorial</a>, <a class='technorati-link' href='http://technorati.com/tag/junit+test' rel='tag' target='_blank'>junit test</a>, <a class='technorati-link' href='http://technorati.com/tag/model+factory' rel='tag' target='_blank'>model factory</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.gwttutorial.com/gwt-autobeans/using-gwt-autobeans-in-junit-tests/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GWT Timer Example</title>
		<link>http://www.gwttutorial.com/gwt-development/gwt-timer-example</link>
		<comments>http://www.gwttutorial.com/gwt-development/gwt-timer-example#comments</comments>
		<pubDate>Wed, 28 Mar 2012 13:52:18 +0000</pubDate>
		<dc:creator>Jeff Richley</dc:creator>
				<category><![CDATA[GWT Development]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[GWT Tutorial]]></category>
		<category><![CDATA[timer]]></category>

		<guid isPermaLink="false">http://www.gwttutorial.com/?p=99</guid>
		<description><![CDATA[GWT Timer Example From time to time, you will run into situations that you need to kick off some code sometime in the future or on a recurring basis.  The folks that have been writing JavaScript code have been doing this for years, but what is the CORRECT way to do this in GWT? You [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gwttutorial.com/wp-content/uploads/2012/03/gwt-timer-example.jpg"><img class="alignleft size-thumbnail wp-image-117" title="gwt-timer-example" src="http://www.gwttutorial.com/wp-content/uploads/2012/03/gwt-timer-example-150x150.jpg" alt="gwt development " width="150" height="150" /></a></p>
<h2>GWT Timer Example</h2>
<p>From time to time, you will run into situations that you need to kick off some code sometime in the future or on a recurring basis.  The folks that have been writing JavaScript code have been doing this for years, but what is the CORRECT way to do this in GWT?</p>
<p>You can always dip down into JSNI (native JavaScript code) and create a timer service for yourself, but why do that when the magical fairies in the Google Wonderland have brought us the <strong>com.google.gwt.user.client.Timer </strong>class?  It is a very simple to use class that kind of has the feel of a classic Thread in Java.  The basic flow of developing with the <strong>Timer</strong> class is to create a timer, make a run() method, and then schedule it for some time in the future.  Here is an example of a <em>GWT Timer</em>:</p>
<p></p><pre class="crayon-plain-tag">Timer t = new Timer() {
public void run() {
// put your code logic here
}
};

// Schedule the timer to run once in 10 seconds.
t.schedule(10000);</pre><p></p>
<p>The schedule method will make sure that your code is called at some time in the future that is at least as many milliseconds as you have specified.  That is an important thing to realize.  Just because you have told the code to run in 10 seconds doesn&#8217;t mean that it will be exactly 10 seconds from now.  This has a lot to do with the fact that the JavaScript engine isn&#8217;t running a bunch of threads at the same time.  It may need to complete what it is doing when the code is to be triggered.</p>
<p>Another option you have is to make your scheduler be recurring.  If you use the schedule() method it will run only once and if you use scheduleRepeating() it will happen on an ongoing basis.  As you can see the process on how to use a GWT Timer is pretty straight forward, nothing all that complicated.</p>
<h3>Other Resources for GWT Timer</h3>
<ul>
<li><a title="GWT Timer Javadoc" href="http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/Timer.html" target="_blank">GWT Timer Javadoc</a></li>
<li><a title="JavaScript Timer Example" href="http://www.w3schools.com/js/js_timing.asp" target="_blank">JavaScript Timer Example</a></li>
</ul>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/example' rel='tag' target='_blank'>example</a>, <a class='technorati-link' href='http://technorati.com/tag/google' rel='tag' target='_blank'>google</a>, <a class='technorati-link' href='http://technorati.com/tag/gwt' rel='tag' target='_blank'>gwt</a>, <a class='technorati-link' href='http://technorati.com/tag/GWT+Tutorial' rel='tag' target='_blank'>GWT Tutorial</a>, <a class='technorati-link' href='http://technorati.com/tag/timer' rel='tag' target='_blank'>timer</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.gwttutorial.com/gwt-development/gwt-timer-example/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.669 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-09-22 15:06:29 -->
<!-- Compression = gzip -->