Wednesday, December 26, 2012

Re: Simple GWT Deferred Binding Example

hello Sir

I read yours eg and try to implement
but i got fail
can u give me this complete eg as a eclipse project

On Friday, March 28, 2008 10:11:50 PM UTC+5:30, neonleon wrote:

I wanted to post a very simple example of GWT deferred binding as I
had trouble initially grasping it.

What this example will do is alert a message to the screen based on a
meta property set in the html page.

Here are the steps:

1.  I am going to create java classes that will alert a message to the
screen.  Each one of these classes will implement an Alerter

        package com.zedak.alerter.gwt.client.impl;

        public interface Alerter {
                    public void alert();

2.  Here are my implementations of the above Alerter interface:

        package com.zedak.alerter.gwt.client.impl;

        public class HelloAlerterImpl implements Alerter{
                    public void alert() {

        public class GoodbyeAlerterImpl implements Alerter{
                    public void alert() {

        public class DefaultAlerterImpl implements Alerter{
                    public void alert() {

3.  I am going to create a property which will be utilized by GWT to
determine which implementation my Alerter will use.  I am going to
define my properties in a seperate XML file than my main module to
reduce clutter...

        Contents of Alerter-properties.gwt.xml:

                    <define-property name="alerter" values="hello,goodbye,default" /

                    <property-provider name="alerter">
                                           var alerter = __gwt_getMetaProperty("alerter");
                                           if (alerter == null){
                                                alerter = "default";
                                           return alerter;

The HTML will contain a meta property that will define which alerter
to use.  If no meta property exists, it will use the default.

4.  I now will inherit the above module in my main module and define
which Alerter implementation to use for each possible property.

        Contents of Alerter.gwt.xml:


                    <!-- Inherit the above module -->
                <inherits name="com.zedak.alerter.gwt.Alerter-properties" />

                                <when-property-is name="alerter" value="hello"/>

                                <when-property-is name="alerter" value="goodbye"/>

                                <when-property-is name="alerter" value="default"/>

                <entry-point class='com.zedak.alerter.gwt.client.AlerterEntryPoint'/

5.  Now lets create the EntryPoint class defined in the above XML,
which will call the Alerter implementation based on the property

        package com.zedak.alerter.gwt.client;

        public class AlerterEntryPoint implements EntryPoint {
                public void onModuleLoad() {
                                Alerter alerter = (Alerter) GWT.create(Alerter.class);

All this module will do is instantiate the appropriate Alerter and
alert the message to the screen.  You must use the GWT.create method
to instatiate the Alerter class.

6.  Finally, lets add the appropriate code to our Alerter.html page...

                            <meta name='gwt:module' content='js/
                            <meta name='gwt:property' content='alerter=hello'/>
                        <script language="javascript" src="/js/gwt/

When you load the Alerter.html file, you should see an alert dialog
that states 'hello'.

If you switch the property to this...

        <meta name='gwt:property' content='alerter=goodbye'/>

You should see an alert dialog that states 'goodbye'.

Removing the property entirely should display an alert dialog that
states 'default'.

I thought a super-simple example might be helpful for some people out
there, and I hope that it is.


You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment