How to access any component within Toolkit application?

Is there a common “registry” or such which allows me to access any component created on Toolkit application?

/ Thank you

I think you refer to this Application main window’s component iterator:

Iterator it = getApplication().getMainWindow().getComponentIterator();
while (it.hasNext()) {
  Component c = (Component);

That gives you all the components which are added into main window container. Of course you have to continue this iteratively for each sub container. Hope this helps.

I could also use such a registry.

Could you add an Application wide identifier namespace for Components? With it, one could set a unique id for a Component, and after that the Component would be retrieveable by the id.

This way one could get a java reference to a certain Component from outside the Application without a need to loop through all the Components within an Application and without a need to create irregular ways of concluding a Component’s identity.

An analogy to this feature would be DOM’s getElementById(id).

Without such a feature in the toolkit I am unable to build implicit relations between my own Component dependent java objects. I could circumvent this issue by setting an id for a Component by invoking the Select’s addContainerProperty (
) for example, but it wouldn’t be very elegant.

To illustrate further, I have a business logic object that affects another similar kind of a business logic object. Their mutual interaction affects the UI immediately (AJAX), but in my java code I can’t do this conveniently without the other object being able to get a reference to the other by id. This is because the code that generates the those objects’ UI, is completely unaware of the surrounding UI engine.

Or have you your selves created some other ways of imitating this kind of functionality?

I think you could use Unique User Interface ID (UIIDs) for these. The component’s method you are looking for is setUIID(String UIID) and String getUIID().

See class com.itmill.toolkit.terminal.Identifiable . This allows you to set unique ID’s for any Toolkit component at any time with Component.setUIID(String UIID) method. Hence, UIIDs are static and they do not change even if server is restarted or application is initialized differently or if source code is changed.

What is missing for your case is “registry”. You could e.g. extend Identifiable class and add “registry” there. Add hashset there and override setUIID in such way that it adds Component to the hashset. Also, add method for getting “registry” hashset => method Component getComponentByUIID(String UIID) is trivial to implement.

Actually Toolkit calculates each Component own identity when component is rendered to browser but this identity depends on the order of application initialization etc. I assume this non deterministic behaviour is a no go for you use case. The result is that you just got to set unique ID’s programmatically in your Java server-side code.

With Toolkit 4, valid pattern for UIID is:


By the way, these UIID’s are usable outside Java server-side too on client-side. It is required by Testing Tools.

Just for a side not: UIIDs have some use cases for building up multi-lingual applications too, but I wont dwell into that discussion with this thread.

Great, thanks!