How to handle events in ZK Webui properly

849 views
Skip to first unread message

Jan Thielemann

unread,
Mar 12, 2013, 10:09:39 AM3/12/13
to idem...@googlegroups.com
Hi,
what i want to do is the following:
I have a custom subclass of WEditor which consists of a textfield and a button. If the button is pressed, i initiate a call via our asterisk telephone system. I don't want to block the ui so i initiate the call via a worker class (subclass of java.lang.Thread) which calls my editor once it has initiated the call. Now i want to change the button image so the user can see that the call is initiated. If he click the button again, i want to end the call. I already did this in the swing client and it works great but in the webui several errors occured to me.

The first error is that if i try to change the button image from the method which gets called by my worker, i get a java.lang.IllegalStateException: Components can be accessed only in event listeners. This is what actually worked in the swing client...

So i tried to post an event but every event i post programmatically causes a NullPointerException because Events.postEvent() makes use of Execution exec = Executions.getCurrent(); when posting events and this is null because my worker is running in another thread.

The next thing i tried is to save the current executions to an instance variable and post my event there but my event never shows up in the editors onEvent() method.
Even if i try to post an event before is start my worker, the event does not show up in my event listener.

I would really like to learn what i am doing wrong and how to solve my problem. Every hint into the right direction is appreciated!

Heng Sin Low

unread,
Mar 12, 2013, 10:13:31 AM3/12/13
to idem...@googlegroups.com

you need to use server push if you want to update zk component in worker thread ( use the serverpushtemplate class ).

--
You received this message because you are subscribed to the Google Groups "iDempiere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jan Thielemann

unread,
Mar 13, 2013, 4:03:35 AM3/13/13
to idem...@googlegroups.com
Hello hengsin,
thank you for the answert. I'll take a look at the serverpushtemplate. I also found another way which works for my special case:

In my WEditor subclass, i add "onMySpecialEvent" to the EVENT_LISTENERS array. Then i can call:

Executions.schedule(AEnv.getDesktop(), this, new Event("onMySpecialEvent"));

from the method which gets called by my worker thread.
 

Heng Sin Low

unread,
Mar 13, 2013, 4:22:29 AM3/13/13
to idem...@googlegroups.com
Internally, the SeverPushTemplate is also using Executions.schedule so it is actually the same approach here.



 

--
Reply all
Reply to author
Forward
0 new messages