-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I'm having trouble implementing something in ZK and thought I'd ask if anyone out there has any suggestions. I'm creating a UI to display and work with a hierarchical data structure within an app already using ZK 3.6.2. Not surprisingly, I went with a ZK Tree backed by a TreeModel - essentially a thin wrapper on top of the hierarchical data. Everything works great for a single user, but problems arose when it turned out that the data structure needed to be accessible to multiple users at the same time.
There will be complexity associated with keeping the data structure thread-safe, but I'm okay with that. The part I'm less sure about is how to keep the visible Trees in sync across multiple desktops. My first thought was to use a singleton TreeModel, maintaining an association between Desktops and their listeners, and then activating the desktops when it was time to fire TreeDataEvents to listeners on other desktops. That didn't work. If you know the ZK event code (better than I do), you'll know that activating desktops is only possible when listener methods are being invoked. Given that the trees are themselves the listeners, I can't easily have them activate their associated desktop when responding to events. I had some thoughts about other approaches, but they all seemed pretty complicated. Any suggestions? (I don't think we'll be moving to ZK 5 in this release of the product, so although I'd be interested to hear about ZK 5 solutions, what I need for now is something that will work with 3.6.x)
Thanks,
Matt
Hi Jumper,
Thanks. I'd already seen that.
If anyone's curious, I ended up taking the following approach. Every user/Desktop gets its own TreeModel. That TreeModel is then registered as a listener using our app's own event tracking mechanism. Whenever changes are made to the underlying hierarchical data, an event is fired to all listening TreeModels (activating and deactivating Desktops as necessary). Those TreeModels then translate the event into an appropriate ZK TreeDataEvent and refire them.
It's not perfect, but it works. When we move to ZK 5, we'll take a look at whether some of our event tracking could be handled by the application-scoped event queues instead.
--Matt
I have a diffrent approach I use in a listmodel.
I built a wrapper as singleton and registered it as Attribute in App-Scope - so it is used in all sessions and Desktops. Perfectly works.
This might be a much easier way.
Cheers,
Timo Goetze
ServerPlusPlus Ltd
@jumper Thanks, I saw that. I'll give it a closer look.
@Timo I think a ListModel would be a close enough analog. Could you describe what you did in a bit more detail? For me, the hard part isn't figuring out how to share the singleton, it's making sure that the ZK events (TreeDataEvents in the case of a TreeModel, ListDataEvents for a ListModel) are fired to all of the Desktops on the correct threads. Is there an easy way to do this that I'm just missing?
Thanks,
Matt
Asked: 2009-12-07 11:46:46 +0800
Seen: 483 times
Last updated: Dec 19 '09