Skip to main content

name property for components?

2 replies [Last post]
fabiobond
Offline
Joined: 2004-12-20
Points: 0

Hi, i've just discovered this amazing Framework and all I can say is that is absolutely brillant.

In the last 2 years I developed my own UI Framwork mainly focused on build dynamic mobi-zines that can be updated downoading resources (magazines editions).

Now I would like to port my applications to this great framework but I've a little problem: I was used to give a name to all my components so when I receive an event from them I can easily decide what to do just evaluating the name.

A simple "name" property (as exists in swing components) will suffice. Actually the only other way I can think about to solve my problem (since the components are added dinamically at runtime parsing an xml resource) is to add an instance of all the objects to an hashmap using the component as key and its name as value: in this way, during event handling, I can retrieve the name property using the event's source property.

I think a name property would be more practical.

What do you think about it?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07
Points: 0

Hi Fabiobond,
the solution of placing all components into a hashtable should work but poses a technical risk of a memory leak so I wouldn't recommend it for a general application.
The ability to store meta-data with a component is a useful one in some cases (although to a lesser degree in CLDC which has no reflection) and I understand the value there, especially with dynamic UI's.
Unless Chen has an objection or a better idea I think that an API similar to Swings: myComponent.putClientProperty(String, Object);
Object o = myComponent.getClientProperty(String);

Should solve your problem and any future use case in this area. It could also enable nifty binding features in the CDC port...

Thanks,
Shai.

fabiobond
Offline
Joined: 2004-12-20
Points: 0

Hi Shai, your suggested solution should be ok.
I Hope to see it implemented in one of the next releases.

Best Regards
Fabio