0

interceptor

asked 2009-12-12 01:05:21 +0800

sanhaq gravatar image sanhaq
264 1 6

Hi All,
Can I write code by which I can capture any event(like onClick,onChange,onSelect,onOpen,onChanging etc.) triggerred on any component in any page in my application. It's just like an interceptor. What I want to do is some preprocessing on any event.Say in my application I have one page where user has to fill up some data to save in database and two button one is 'Save' another is 'Cancel'.Now if user after filling data instead of 'Save' button clicks 'Cancel' which will take the user away from that page then it will call the method onClick$buttonId(Event e) but is it possible to write code that before calling the method onClick$buttonId(Event e) I can capture the event and do some preprocessing like if any unsaved data is there in the page it will give one warning. It's just a simple example but in complex scenario like that before said page after user filling data can exit from that page pressing 'Cancel' button or selecting an item from drop down, pressing 'Logoff' link or closing the window itself. So is there any way to implement interceptor to catch and handle Ajax call before calling its conventional [event$id(Event e)] method of Composer.

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2009-12-12 06:00:30 +0800

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

public class YourController extends GenericForwardComposer 

   ...

	@Override
	public void onEvent(Event evt) throws Exception {
		final Object controller = getController();
		final Method mtd = ComponentsCtrl.getEventMethod(controller.getClass(), evt.getName());

		if (mtd != null) {
			// your stuff here.
		}
		super.onEvent(evt);
	}

Only a hint.
I store the init values of the data. If the user is modifying something then a flag isChanged() is set to true.
By closing a window i check the isChanged method and ask the user for changing the modifications.

best
Stephan

link publish delete flag offensive edit

answered 2009-12-12 07:56:06 +0800

sanhaq gravatar image sanhaq
264 1 6

updated 2009-12-12 07:56:43 +0800

Stephan
Thanks a lot.
By the way I read from one thread in this forum that we can't capture the event of closing the window without using the window.onbeforeunload javascript staff. is it rght? Can't I do the preprocessing wihtout using javascript/zscript?
I have read 3 points poted by you
"1. decrease the SessionTimeout
2. take a Conection Manager. Hibernate have its own session and handles them.
3. Let tomcat hold the connection to the database"
this is the alternatives. can I call any method while user closes the window?

link publish delete flag offensive edit

answered 2009-12-12 11:13:52 +0800

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

If i do capture the closing of a window i always mean closing a modal window.
A web app is not equal like a native Desktop app. When a user closes the browser how you could capture the closing of the zkoss app in a browser page?.

To the 3 points. I don't know at time in wich context i have said this. But seems not in a case of closing a window?

best
Stephan

link publish delete flag offensive edit

answered 2009-12-13 18:54:21 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

updated 2009-12-13 18:54:53 +0800

@sanhaq,

This might be what you want?

http://www.zkoss.org/javadoc/3.6.3/zk/org/zkoss/zk/ui/util/EventInterceptor.html

link publish delete flag offensive edit

answered 2010-01-01 09:43:09 +0800

sanhaq gravatar image sanhaq
264 1 6

happy new year to you all,
@henrichen
I used the EventInterceptor
and I saw every time when an event is triggered 'beforePostEvent' of EventInterceptor gets invoked as
I have added the listener in my doaftercompose.But if I close the browser will this event be captured by
any of this methods (afterProcessEvent,beforePostEvent,beforeProcessEvent or beforeSendEvent) ?
I think no right?

link publish delete flag offensive edit

answered 2010-01-01 10:03:12 +0800

sanhaq gravatar image sanhaq
264 1 6

hi all,
My problem can be solved using DesktopCleanup interface
thank you all,

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: 2009-12-12 01:05:21 +0800

Seen: 1,185 times

Last updated: Jan 01 '10

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