-
FEATURED COMPONENTS
First time here? Check out the FAQ!
All,
Would like to request some help with understanding the mechanism on how server side events can be fired and handled by custom components.
Trying to build an extended text box and subscribe to say "page refresh" event that ViewModel would throw.
- In my TextBox class I'm doing:
static {
addClientEvent(ExtendedTextbox.class,
PageRefreshEvent.PAGE_REFRESH_EVENT,
CE_IMPORTANT | CE_DUPLICATE_IGNORE |
CE_NON_DEFERRABLE); } Where
PageRefreshEvent is my event.
- I'm overriding method void service(org.zkoss.zk.au.AuRequest
request, boolean everError) and
checking cmd for
PageRefreshEvent.PAGE_REFRESH_EVENT a standard approach
- Here's I need to fire an event from my ViewModel to notify all my
text boxes that page was refreshed,
but I don't see how it can be
achieved. Tried several ways a)
Events.postEvent(new
PageRefreshEvent(this)); b)
EventQueues.lookup(<queue_name_referred_from_zul>,
BinderCtrl.DEFAULT_QUEUE_SCOPE,
false); que.publish(new PageRefreshEvent(this));
I don't see that service method in my text box is ever called with page refresh. Looks like the only type of events textbox component is intercepting is events fired from textbox widget and wrapped into AuRequest.
So the question that I have: is there any way to emulate a "page refresh" event for all the controls on the desktop? Somewhat similar to BindUtils.postNotifyChange() but with my own custom event type?
Thanks a lot in advance!
Hello, try :
In your MyTextBox class constructer:
this.addEventListener(PageRefreshEvent.PAGE_REFRESH_EVENT, new EventListener() {
public void onEvent(Event event) throws Exception {
Object[] data = (Object[]) event.getData(); // some data from client
}
});
In your service method:
final String cmd = request.getCommand();
if (Events.ON_CHANGE.equals(cmd)) {
Events.postEvent(PageRefreshEvent.PAGE_REFRESH_EVENT, this, someData);
}
It's fully server-side solution. Actually, you aren't making a pure ZK component but reuse the textbox provided by ZK. We simulate custom PageRefresh Event by using ON_CHANGE event from ZK textbox.
If you want to make a total pure ZK component by yourself, you need to write javascript and implement those event both in client-side and server-side.
Asked: 2014-03-20 16:32:01 +0800
Seen: 49 times
Last updated: Mar 24 '14