Revision history [back]

click to hide/show revision 1
initial version

answered 2012-07-24 05:36:43 +0800

simonmassey gravatar image simonmassey

I think that using @GlobalCommand for communication between ViewModels is a nicer way to do this. See this post http://stackoverflow.com/questions/11505371/how-to-get-a-viewmodel-from-another-viewmodel-in-zk-framework which is asking how a main window can pass the current selected item to a popup window. Clearly we can go back the other way by having the popup window use a @GlobalCommand to have a popup window pass a value back to the main window.

The reason why I prefer using @GlobalCommand in the zul rather than raising the global command in Java is the "no surprises" rule. With normal MVVM you can look at the ZUL file to know how the ViewModel is notified and you can look at the ViewModel to know how the business services are used. As soon as you use "BindUtils.postGlobalCommand(...);" inside a view model we have a "surprise" that an @Command also invokes a global command internally. If you move the posting of the global command back to an "@GlobalCommand" in the ZUL then you remove this "surprise" behaviour and you can easily see from the ZUL which components invoke local commands and which components invoke global commands.

Another way to look at it is that architecturally the Binder is part of the View framework which should be kept as separate as possible from your models. In terms of this presentation about patterns http://www.slideshare.net/simbo1905/design-patterns-in-zk-java-mvvm-as-modelviewbinder the ViewModel contains the business logic so should avoid calling the Binder which is part of the View.

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