0

Capturing all click events

asked 2012-11-27 19:00:37 +0800

iank gravatar image iank
42 4

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

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2012-11-28 18:19:39 +0800

gekkio gravatar image gekkio flag of Finland
899 1
http://gekkio.fi/blog

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.

link publish delete flag offensive edit

answered 2012-11-28 22:20:24 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2012-11-29 00:23:04 +0800

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);
	}

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-11-27 19:00:37 +0800

Seen: 246 times

Last updated: Nov 28 '12

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