View Full Version : Registry usage

29 Apr 2008, 7:47 AM
Hi all.

I'm having some difficulty with the registry. In the description it says it's a local store for objects and I understand it's a Map.

Are there limitation to what can be put in there? For example I hold the Client (logged in user) username for easy access. Here's some code:

rules = new RuleSetMap();
tasks = new RuleSetTasks();
editor = new RuleSetEditor();

clientName = new String("svadmin");

Registry.register("rulesmap", rules);
Registry.register("tasks", tasks);
Registry.register("editor", editor);
Registry.register("clientname", clientName);

Info.show("Client Name", "Something", (String)Registry.get("clientname"));

Bear in mind RuleSetTasks/Editor are widgets I've created and RuleSetMap is a map. They hold references I can use from other Widgets. Any idea why the String is not being registered?

What would be the correct usage for the Registry. I want to able to use it as a global (Yuck!!!) store for a rough demo I'm doing.


29 Apr 2008, 8:09 AM
You can put any object in Registry, it's just a Map<String,Object>.
But the Info.show method ultimately calls Util.Format which relies on {} placeholders to format the string. Try this,

Info.show("Client Name", "Username: {0}", (String)Registry.get("clientname"));

29 Apr 2008, 1:28 PM
Is the Registry completely global or is limited by package or something.

That worked by the way but I was only doing that as a test. My main problem is I try to access the data elsewhere in the app and it returns null. The code below presents a problem cos the editor uses the client within its constructor.

editor = new RuleSetEditor();
clientName = new String("svadmin");
Registry.register("clientname", clientName);

I corrected this by making sure the string is created and registered before the editor is created like so:

clientName = new String("svadmin");
Registry.register("clientname", clientName);
editor = new RuleSetEditor();

Now when I debug and break at the RuleSetEditor constructor Registry.get("clientname") returns null. Any ideas?


29 Apr 2008, 1:42 PM

The Registry map is static instance and availble globally to the JVM instance that is running your application (not sure what happens in JS but I'm guessing Google takes care of that).

You access that static instance through static methods etc... all good.

Can you describe in detail what you are doing (ie in hosted mode?) and how big is your app (meaning is it broken-up into parts, if so how etc). I'd doubt the Registry would survive history refreshes unless its tied into Google history state model - and it doesn't look like it is... but I'm not 100% on that.

29 Apr 2008, 1:46 PM
MI - more to the point of what you are trying to do...

Are you trying to store username/pwd stuff in state? If so, I've taken this approach.

Stored a hash-token in a cookie that I interogate when needed, the hash-token is issued by the RPC Servlet when I authenticate - the token is only valid for a session (ie it eventually timesout) and I even refresh (replace) the token on every RPC call.

I would suggest you DONT store the user/pwd in a cookie - but storing a temp auth-token is fine as after use, its useless anyways....

29 Apr 2008, 2:08 PM
Hi gs,

Ok. It's a demo so I've not designed it to take care of history nor is it necessary to really handle thorough authentication. Secondly I don't intend on storing usename/passwd for authentication purpose but they will be available in a cookie if need be(my boss is creating a secure login jsp that then redirects to my app upon successful login).

The basic idea is I provide an app for a user to edit rules in java that are run on the server usnig a tool my boss developed.
There are two main tabs edit and view.
Edit tab represents the the editor (a content panel with a richtextarea and some buttons) and the rules manager (another content panel with list box and some buttons).
View tab I'll ignore for except to say when these rules are ran on the server the tool products jpeg data which I then load in dynamically every few mins (still attempting to load dynamic images but that's for another day another post).

So upon appload the rules list is populated with an RPC call. Rules (and JPEG results) are stored in a folder on the server and this is where I use the client name to provide part of path to the store. I've a server config xml file that holds the paths to the various folders but the client name is the key. After I've the rules list RPC calls are used to load in the rule contents to the editor's richtextarea.

It's a simple enough app and if we take it further then it'll be ripped apart anyway.

You mentioned about using the static Registry store from static methods but I only use instance methods on the client side but I'm sure since it's static I can do that.

Thanks for reply,

16 Oct 2013, 11:13 PM
What happend to this future in ext gwt version 3 ??