Indeed, that would ben a better options. You don't need to sobscribe the queue in the init, just target the event in zul to that command
chillworld ( 2018-12-01 00:33:03 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
In my VM, i'me listening an event queue and trying to put an notice to the user. but postNotifyChange fail. i had to handle component to make the client be notified. is there a better way to do it in VewMmodel ?
@Init
public void init() {
EventQueue<Event> eq = EventQueues.lookup("postNotice", EventQueues.APPLICATION, true);
System.out.println("subscribing event.");
eq.subscribe(new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
System.out.println("received event in homeVM");
msg = .....
BindUtils.postNotifyChange(null, null, this, "msg"); // msg is always refreshed, even without this.
BindUtils.postNotifyChange(null, null, this, "msgvisible"); // this never notice the client.
}
}
}
Okay,
Now we are getting there.
the information from another session is of course very crucial.
Please look at the following small talk.
https://www.zkoss.org/wiki/SmallTalks/2014/March/ChatwithGlobalCommand
It will explain you on how to achieve the same, without any personal use of the eventQueue (the global commad will work with eventqueue but that is abstracted out)
The example calls first a command in order to not explose it t all the other sessions, the gobal command is then exposing to all other sessions.
Chill.
I would start with mixing MVC and MVVM is never good and you could use Command
and GlobalCommand
as a better way to use the Queue's in MVVM.
But I also notice the keyword this
.
Where do you think that will be targeted? It's your eventlistener, not you Viewmodel!
To pass the viewmodel instance ClassName.this
.
Chill.
Thanks for you answer. i used ClassName.class before but not work ,ater that i changed it to "this",still not work.
use command do you mean like this :
@Init
public void init() {
EventQueue<Event> eq = EventQueues.lookup("postNotice", EventQueues.APPLICATION, true);
System.out.println("subscribing event.");
eq.subscribe(new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
doRefreshMsg(event.getDate());
}
}
}
@Command
@NotifyChange ("*")
public void doRefreshMsg(....){
//do something here.
}
Indeed, that would ben a better options. You don't need to sobscribe the queue in the init, just target the event in zul to that command
chillworld ( 2018-12-01 00:33:03 +0800 )editthanks for your suggest. i tried to invoke the command in the eventlistener, the command executed successfully, but the @NotifyChange not work in this situation.
the second way, i've tried too. but failed to receive the event. my event is sent from another session (by another user) and this event couldn't be received by a component in another session. i did like this :
// when a user post an article in post.zul:
eq.publish(new Event("onInvitePost", Path.getComponent("//main/home"), myMsgBean));
in another page:
//notify another user who was invited :
in home.zul:
<?page title="main" id="main" contentType="text/html;charset=UTF-8"?>
<borderlayout id="home"
viewModel="...."
onInvitePost="@command('doInform',e=event)">
...
and in VM:
@Command
@NotifyChange({ "msg", "msgvisible" })
public void doInform(@BindingParam("e") Event e) {
System.out.println(" onIvitePost received in notice...");
Clients.showNotification("doInforming");
}
as a result, the command doInform never execute. event of Desktop Scope could be send to a special target ,but this case is a Application Scope event queue. sames it has to define an event queque in somewhere and sign an event listener in the event queque.
Thank you very much! It works perfectly! Great global command! just a postGlobalCommand solves all problem. there's no need to sign an eventQueue manually any more.
Further more, does postGlobalCommand need to be in an Execution ? if the command was launched by some other event instead of another session(eg.sth changes in database, or Pay Notice from bank) .
if it works, seems that there's no need to sign an event queue manually any more ,do you agree ?
In MVVM there is indeed very little need of manual triggering the eventqueue. Almost everything can be done with command and globalcommand. Just going from 1 user session to another user session is some specific knowledge.
chillworld ( 2018-12-04 17:13:03 +0800 )editAsked: 2018-11-26 13:24:51 +0800
Seen: 23 times
Last updated: Dec 04 '18
[Smalltalk] Template Examples -Locker
Custom- Session TimeOut Message [closed]
No invisible modal window in class deriving Window [closed]
Update from ZK 8.0.2.2 to 8.5.0 (with ZK-Studio)
Popout ZK Tab to Browser [closed]
SCRIPT: Permission denied in IE11 and Edge
'Problems encountered while deleting resources' for Zk-Spring-Boot project