GWT's i18n interface null b/c hidden by isDesignTime

GWT Designer allows you to quickly create the modules, composites, panels, remote services and other elements that comprise Google Web Tookit applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

GWT's i18n interface null b/c hidden by isDesignTime

Postby allioop70 » Tue May 22, 2007 2:44 pm

We have a base class that all our "panels" derive from, because we are using internationalization, the i18n constants class is used by all our "panels" so we have added it to the base class.

Code: Select all
public class BaseWidget extends Composite
{
  public static i18nConstants ouri18nConstants = null;

  public BaseWidget()
  {
    if (ouri18nConstants == null)
    {
      if (!isDesignTime())
      {
        ouri18nConstants = (i18nConstants)   GWT.create(i18nConstants.class);
      }
    }
  }
}


This is all fine and good, except that when you go to use the Design View of Designer, ouri18nConstants is null, so the page doesn't render and the log shows NullPointerException for each call to a method in the i18nConstants class.

If we don't use the isDesignTime method, the pages won't render either b/c Designer can't instantiate the i18nConstants class in Design View.

Example: In a derived class:
Code: Select all
Label panelHeaderLabel = new Label(ouri18nConstants.header());


Is there a way around this problem?

Thanks!
allioop70
 
Posts: 13
Joined: Mon Jan 29, 2007 2:57 pm
Location: Colorado

Re: GWT's i18n interface null b/c hidden by isDesignTime

Postby Eric Clayberg » Wed May 23, 2007 5:10 am

You need to follow the pattern shown in our Internationalization docs and assign your constants directly to a static final field.

Here's an example...

Code: Select all
import com.google.gwt.i18n.client.Constants;

public interface AppConstants extends Constants {
   String button_text();
   String button2_text();
}

Code: Select all
#GWT variable: CONSTANTS
#Wed May 23 11:16:15 MSD 2007
button_text=New Button
button2_text=My second button

Code: Select all
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.mycompany.tutorial.client.AppConstants;

public class BaseWidget extends Composite {
   protected static final AppConstants CONSTANTS = (AppConstants) GWT.create(AppConstants.class);
   private AbsolutePanel absolutePanel;
   public BaseWidget() {
      {
         absolutePanel = new AbsolutePanel();
         initWidget(absolutePanel);
         absolutePanel.setSize("100px", "100px");
         {
            final Button button = new Button();
            absolutePanel.add(button, 156, 158);
            button.setText(CONSTANTS.button_text());
         }
      }
   }
   public AbsolutePanel getAbsolutePanel() {
      return absolutePanel;
   }
}

Code: Select all
import com.google.gwt.user.client.ui.Button;

public class MyPanel extends BaseWidget {
   public MyPanel() {
      {
         final Button button = new Button();
         getAbsolutePanel().add(button, 28, 38);
         button.setText(CONSTANTS.button2_text());
      }
   }
}

Also make sure that you are using the latest GWT Designer build.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: GWT's i18n interface null b/c hidden by isDesignTime

Postby allioop70 » Wed May 23, 2007 8:14 am

I believe I mentioned in my post that assigning it directly was what we tried first and it didn't work. Almost exactly like the code you posted above. Designer wouldn't draw the screens because it wouldn't instantiate the constants, as soon as we wrapped it with the isDesignTime method, the screens would draw in Designer, but when we used the constants class, it stopped drawing again because the constants class is null at design time.

This is what we had originally in our base class:
Code: Select all
public static final i18nConstants ouri18nConstants =
      (i18nConstants) GWT.create(i18nConstants.class);


What we have now was posted above.

We are using that latest stable build, 1.7.1.


Eric Clayberg wrote:You need to follow the pattern shown in our Internationalization docs and assign your constants directly to a static final field. <SNIP>
Also make sure that you are using the latest GWT Designer build.
allioop70
 
Posts: 13
Joined: Mon Jan 29, 2007 2:57 pm
Location: Colorado

Re: GWT's i18n interface null b/c hidden by isDesignTime

Postby allioop70 » Wed May 23, 2007 9:24 am

Okay, so I found that the Designer generated i18n properties file adds the following line that GWT itself doesn't use

Code: Select all
#GWT variable: ouri18nConstants


So, after adding that line to our properties file, I am now seeing all my properties in Designers Externalize Strings dialog.

However, I still cannot use our pre-existing key/value pairs, but if I add a new one, using the externalize wizard, it works.

What is Designer doing behind the scenes that only key/value pairs externalized by Designer work?

BTW, I still have the instantiation of ouri18nConstants wrapped with isDesignTime b/c it does not work otherwise.
allioop70
 
Posts: 13
Joined: Mon Jan 29, 2007 2:57 pm
Location: Colorado

Re: GWT's i18n interface null b/c hidden by isDesignTime

Postby Eric Clayberg » Wed May 23, 2007 9:36 am

Are you saying that the example I posted above does not work on your end?

Here are screen shots of what it looks like on my end...

Image Image

Please give my example a try and let me know if it works. If it works, then post (or e-mail) a detailed example (using the same pattern) that does not work.

There must be some difference that accounts for this working on my end and failing onyour end.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to GWT Designer

Who is online

Users browsing this forum: No registered users and 3 guests