[Image] EchoPoint
Helping you build truly dynamic and stateful web applications!

Component identifier on roids!

By Brad Baker
Tuesday, May 25, 2004


Each nextapp.echo.Component has a single identifier, provided via is getIdentifier() method.  This is great because one is always naming objects during application development.

The problem is that the same object may have many different names or monikers, when used in different ways. 

For example suppose you name a TextField 'last name' because it is used to enter in a 'last name' value.  So you do this :

TextField tf = new TextField();
"last name");

Whats wrong with that I hear you ask?  Well nothing really.

However when you go to store it in a database, you might want to name the field 'surname' because that is what it is called in the table structure.  But its two late cause its already named 'last name'.  OK so you can work around this one.

But if you want to use the EchoPoint CSS support, you may want to use a "generic" identifier to get CSS properties for fields that are for data entry.  Therefore you will name this TextField only with many others, 'dataEntry'.  Ahh but you cant because its already named 'last name' or 'surname' or whatever.

And often you will want to associated some application object alongside the Component that will be used to get data for it.  Now you are truly in strife since this is not a name at all but some "code" object. 

All of a sudden Component.getIdentifier() does not seem like enough.  Well there is good news. 

EchoPoint has a echopoint.util.IdKit class that allows you to have "multiple, named" objects inside the one identifier.  I call it "attributed identifiers" and its very simple.

Basically IdKit has get and set methods that allows you to retrieve and place objects into an identifier by name.  It also has some shortcut methods that work on Components directly.  For example :

TextField tf = new TextField();
IdKit.set(tf,"displayName","last name");
IdKit.set(tf,"appObj", new AppObject());

Under the covers, the IdKit supports both java.util.Map and java.util.Dictionary as identifier objects and places the attributes values in the map under the provided attribute name.  If you call set() without an identifier in place, it will add a new HashMap as the identifier initially.  So in the above example the attributes names and values are being stored in a Map set as the TextField's identifier. 

IdKit also supports java.lang.String values in the identifier and recognises a CSS-like format of

"attrName1:attrValue1; attrName2:attrValue2;...". 

If IdKit detects that the identifier is actually a String, then it will convert any attributes values to Strings (via Object.toString() ) and place them in the identifier.  This allows you to specify identifier values like this :

TextField tf = new TextField();
"validationName:'surname'; displayName : 'last name';");
// the Component identifier is now the java.lang.String    "validationName:surname;displayName:'last name';databaseName:surname"

Note how it also supports quoting within the identifier String.  Whitespace is not considered significant unless its in quotes.

If IdKit detects that the identifier is neither a Map, Dictionary or String, then it does nothing on set and always returns null on get.

With this attributed identifier mechanism you are now free to use the one well defined field, Component identifier, for a myriad of purposes and also it allows libraries such as EchoPoint to offer more generic services.

In fact the CssStyleSheet support has been updated to look for identifier attributes called "style" and "styleGroup".  Also the new echopoint.validation support looks for an identifier attribute called "validationName".

The CssStyleSheet code uses a two stage strategy.  First it looks for an attribute value named "style".  If it can be found, then it uses the Component identifier as a whole.

That way the "more specific" means is used first and then the "least specific" means.  The code is something like this :

Object id = IdKit.get(component,
if (id == null)
      id = component.getIdentifier();
if (styleEntry.getName().equals(id)) {


SourceForge Logo

The EchoPoint project is kindly hosted by SourceForge