0

How to run a view model command when all zk components have been loaded?

asked 2012-06-22 09:04:49 +0800

xeridia gravatar image xeridia
47 1

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

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2012-08-17 04:21:51 +0800

hawk gravatar image hawk
3225 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2012-08-17 04:22:13 +0800

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

link publish delete flag offensive edit

answered 2012-06-23 02:40:53 +0800

Jales gravatar image Jales
161 1

updated 2012-06-23 02:42:28 +0800

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."

link publish delete flag offensive edit

answered 2012-06-23 02:09:27 +0800

Jales gravatar image Jales
161 1

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.

link publish delete flag offensive edit

answered 2012-06-22 11:04:53 +0800

xeridia gravatar image xeridia
47 1

But @Init method is executed before all zk components are loaded. I need execute a view model command when all components (included scripts) are loaded

link publish delete flag offensive edit

answered 2012-06-22 10:32:08 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

You can use @Init Method.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-06-22 09:04:49 +0800

Seen: 226 times

Last updated: Aug 17 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More