-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi there,
Do click events bubble up, and if so, where?
I would like to have a simple function that is called anytime the user clicks on an interface element which initiates an action. Where could I put this?
Thanks!
Ian
No, events do not bubble up (e.g. in Javascript). You can achieve a limited similar effect by using forwarding, but that will have to be done manually.
If you see any documentation that mentions "propagation", in ZK that just means the sequential execution of event listeners applied to a one common component. So, if you have added multiple event listeners to one component, you could stop propagation in the first one, and the latter ones would never see the event.
For your use case you can take a look at page.addEventListener, but I would strongly recommend you to figure out some other approach than that. Adding event listeners to all components on the page can have a huge negative effect on complex pages, and will not work for dynamically added components.
You can try to catch the onEvent method from the superclass of your controller. Works only for coded event methods.
public class MyTestComposer extends GenericForwardComposer { . . . @Override public void onEvent(Event evt) throws Exception { final Object controller = getController(); final Method mtd = ComponentsCtrl.getEventMethod(controller.getClass(), evt.getName()); // System.out.println(mtd.getName()); // do your stuff here super.onEvent(evt); }
Asked: 2012-11-27 19:00:37 +0800
Seen: 246 times
Last updated: Nov 28 '12