Global variables in my GWT App

577 views
Skip to first unread message

Dimedrol

unread,
Aug 28, 2007, 9:13:03 AM8/28/07
to Google Web Toolkit
I have a GWT application, which creates and uses many classes from
different source files.
In my application I use multilanguage interface.
I'm setting the captions for my Labels and Buttons, after reading them
from xml-files as RPC,
using "gwt-ext" library (code.google.com/p/gwt-ext/)
and it's methods of Storage, Load Storage (from xml) and so on.

Each new created class reads it's related xml file with captions and
sets the values.
But, I think it is now very optimal way.

When I'm reading this
I see that sometimes it takes too long to read (and parse!) all data
from xml-files (10-20kb size)
and I've got errors, when my engine cannot find proper caption for
control - it is not loaded yet. :-(

So, my question will be: is there any way to speed-up such kind of
caption's data loading,
or maybe there is a GLOBAL memory area available in GWT,
where I could read some data into, when my application starts, and
then - just read from this global storage all data I need ?! (from my
new run-time created classes)

rb

unread,
Aug 28, 2007, 10:40:38 AM8/28/07
to Google Web Toolkit
Just create a Singleton or a static class with static methods to hold
your global data.


We are using the following on the GWT client side that gets loaded on
start up:

public class ClientSession {

private static Map objects = new HashMap();

public static Object getObject(String key)
{
return objects.get( key );
}

public static void addObjects(Map objs)
{
objects.putAll( objs );
}

public static void addObject(String key, Object object)
{
objects.put( key, object);
}

public static void removeObject(String key)
{
objects.remove(key);

Dimedrol

unread,
Aug 31, 2007, 5:10:51 AM8/31/07
to Google Web Toolkit
So....
At application startup I'll create an instance of this class and put
some global data inside...
"addObject(String key, Object object)"

and for example, my Main class creates some other instances of
classes,
let's say - class Core(.java) creates instance of class
MyDIalogs(from .java file)
and this new class MyDIalogs(.java) creates a class
OneDialogWindow(.java)

class Core --> class MyDIalogs --> class OneDialogWindow

How can I pass, for example, String WinTitle="Hello window"; created
(added) in this static "public class ClientSession" or my "Core"
to the instance of my last mentioned "class OneDialogWindow(.java)" ?

Is it possible?

Axel Kittenberger

unread,
Aug 31, 2007, 6:13:31 AM8/31/07
to Google Web Toolkit
You don't need to instance a static class, use it this way:
ClientSession.addObject("someString", object);
(Object orientation basics, sheeesh)

Dimedrol

unread,
Aug 31, 2007, 7:08:57 AM8/31/07
to Google Web Toolkit
Thank you! It works in GWT!

Reply all
Reply to author
Forward
0 new messages