-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Using ZK 6.5.3 MVVM.
I'm trying to communicate events between different clients, different browsers running my application.
I thought that BindUtils.postGlobalCommand(null, APPLICATION, "somethingChanged", null) would be enough to send the event and @GlobalCommand(value = {"somethingChanged"}) to receive it. But I can't get this to work, my @GlobalCommand is never called.
Isn't this the correct way to do it in the MVVM style ?
Now your problem lies here :
http://books.zkoss.org/wiki/ZK%20Developer's%20Reference/MVVM/Data%20Binding/Global%20Command%20Binding#Notification
The most important here is :
By default we can bind an event to any ViewModel's global command within the same desktop.
Application scope is higher then the desktop scope so we need to search how we can bind the global command to the application scope in stead of the desktop scope. I'm searching for it but at the moment little succes with it.
edit :
Found the solution :
You have to set the binder level to application like this :
<window apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('be.chillworld.YourVM')" binder="@init(queueScope='application')">
and in the vm :
@Command
public void buttonClick () {
....
BindUtils.postGlobalCommand(null, EventQueues.APPLICATION, "refresh", null);
}
@GlobalCommand
public void refresh () {
....
}
you can also give a name to the "binder"so if you have multiple you can call just that queue like this
binder="@init(queueName='refreshIndex', queueScope='application')">
and in the VM you do this :
@Command
public void buttonClick () {
....
BindUtils.postGlobalCommand("refreshIndex", EventQueues.APPLICATION, "refresh", null);
}
edit : The documentation here
Greetz chill.
Hey William,
Normally it's the binder who is subscribed to to scope. If you want to work in 2 scopes you need 2 viewmodels.
If it was me I should do this :
Create normal viewmodel, and another one subscribe to the application scope. In the application viewmodel you have a global-command (what resembles your application command). The first one you set a normal command for the viewmodel and there you call the global command with all the parameters what's needed.
Can you give this way a try?
Chill.
Asked: 2014-01-30 13:06:33 +0800
Seen: 226 times
Last updated: Aug 17 '15
How to Call Child ViewModel Method from Parent Window? [closed]
@global-command, how to set queueName when invoke globalCommand?
how can i get data from another page
Form validation before global command
Post Global Command From Listener
Equivalent to global command on MVC ?
Why does the order of NotifyChange may alter the result of the objects?