David Chandler's Journal of Java Web and Mobile Development

  • David M. Chandler

    Web app developer since 1994 and Google Cloud Platform Instructor now residing in Colorado. Besides tech, I enjoy landscape photography and share my work at ColoradoPhoto.gallery.

  • Subscribe

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 223 other followers

  • Sleepless Nights…

    October 2009
    S M T W T F S
  • Blog Stats

    • 1,033,665 hits

GWT easy i18n with GIN

Posted by David Chandler on October 2, 2009

Short version, from the GIN tutorial:

Note that if GIN can’t find a binding for a class, it falls back to calling GWT.create() on that class. What this means that image bundles and translated messages will just magically work.

Longer version
Suppose we have some GWT Constants we want to make available application-wide. We have our usual Constants interface

import com.google.gwt.i18n.client.Constants;

public interface MyConstants extends Constants {
	String copyright();
	String logoPath();

and the corresponding MyConstants.properties in the same package:

copyright=Copyright 2009 David M Chandler All Rights Reserved.

Now suppose we don’t want to call GWT.create() on it in every class in order to save resources. Thanks to the GIN capability mentioned above, any class created with GIN (which is all views and presenters if you’re using gwt-presenter) can simply do this:

	private MyConstants constants;

There’s no need to create a binding for MyConstants in our GIN module for the above to work, but to get singleton behavior, which is the whole point of this exercise, we must bind it as such in our GIN Module:


Now we’ve theoretically saved some memory and/or CPU by using a singleton, although I wouldn’t be surprised if GWT.create() already does this optimization for Constants and Images…

3 Responses to “GWT easy i18n with GIN”

  1. Jeff said

    Couldn’t you add @Singleton to your interface eliminating the need to add your binding? I know that would work for a class but I’m not sure with interfaces.

  2. […] In similar fashion, I define a corresponding BaseView that eliminates the need for the startProcessing() and stopProcessing() methods required by gwt-presenter’s WidgetDisplay interface. Besides eliminating boilerplate, I use the base view constructor to inject references to my applications Constants and Images singletons (see this previous post): […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: