-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
I am not able to automatically update the data displayed in a grid when the model is changed by some thread in the application.
The ZUL file defines a grid which displays data from the model and a button that will refresh the data in the grid.
ZUL file:
<button label="Update Status" onClick="@global-command('update')" /> <grid model="@bind(vm.targetStatusList)"> ... </grid>
... @GlobalCommand @NotifyChange("targetStatusList") public void update(){ logger.debug( "Global Cmmmand 'update' called , event received. NotifyChange !"); } ...
@Init public void init(){ if (que == null) que = EventQueues.lookup("statusUpdate", EventQueues.APPLICATION, true); que.subscribe(new EventListener() { public void onEvent(Event evt) { logger.debug( "EventListener(): Event received, updating View ..."); update(); } }); }
The annotation @NotifyChange is a *HINT* to the "ZK Binder". It tells the "ZK Binder" that it should update UI components that relative to the specified data whenever the annotated command is executed.
In case1, when you press the button, the onClick event sends a global command "update" to the "ZK Binder" to execute the update() command. So the "Binder" get the chance to read the "HINT" and update the grid. As specified in your zul page:
<button label="Update Status" onClick="@global-command('update')" ></button>
In case2, update() method is called directly via another thread so the "ZK Binder" HAS NO IDEA what happened in this operation. Thus the @NotifyChange is "meaningless" in such situation.
To handle the issue, you have to send the global command to "ZK Binder" and let it do the update() command for you instead calling update() directly. ZK provide an utility method to do this. You should call
BindUtils.postGlobalCommand(null, null, "update", null)
in your thread.
http://www.zkoss.org/javadoc/latest/zk/org/zkoss/bind/BindUtils.html#postGlobalCommand(java.lang.String, java.lang.String, java.lang.String, java.util.Map)
Asked: 2012-08-06 12:23:06 +0800
Seen: 179 times
Last updated: Aug 08 '12