0

How to fire custom events from server-side

asked 2014-03-20 16:32:01 +0800

demichev gravatar image demichev
0 2

updated 2014-03-20 17:14:12 +0800

sitansu gravatar image sitansu
2254 13
http://java91.blogspot.in...

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!

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-03-24 10:36:22 +0800

roliroli gravatar image roliroli
164 4

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.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-03-20 16:32:01 +0800

Seen: 49 times

Last updated: Mar 24 '14

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