-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I am working with ZK 6.0.1. I use MVVM pattern. I want execute a view model command when all zk components have been loaded. How I can do?
Thanks in advance
Hi,
since 6.0.2 you can use @AfterCompose in a ViewModel
http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/MVVM/Advance/Wire_Components
Btw, if you want it to execute a method in your ViewModel from the doAfterCompose(), you might want to try it like this :
a. Trigger an event ( I think you can name it anything you want) on your component. Check this for triggering event manually : http://books.zkoss.org/wiki/ZK_Developer's_Reference/Event_Handling/Event_Firing
b. In your ViewModel, wire the event listener ( http://books.zkoss.org/wiki/ZK%20Developer's%20Reference/MVVM/Advance/Wire%20Event%20Listeners )
to listen to the event, and do what you want.
But, please evaluate this line from the documentation above :
"We do not recommend this usage because it loses ViewModel an important advantage i.e. loose coupling with View. Please evaluate the trade-offs before using it."
Working with MVVM pattern, you might want to work with SelectorComposer too.
For the .zul you created, you can do this :
1. create a Composer that extends SelectorComposer, and then override the doAfterCompose method of SelectorComposer to implement your own code, but DO NOT FORGET to call the super.doAfterCompose() in the first line of your doAfterCompose() method. The doAfterCompose() is (according to the documentation) : "Invokes after ZK loader creates this component, initializes it and composes all its children, if any." ( http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/select/SelectorComposer.html#doAfterCompose(T) )
2. Then, just apply this Composer to your .zul file to your target component.
You can use @Init Method.
Asked: 2012-06-22 09:04:49 +0800
Seen: 226 times
Last updated: Aug 17 '12