-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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.
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
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?
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
@sanhaq,
This might be what you want?
http://www.zkoss.org/javadoc/3.6.3/zk/org/zkoss/zk/ui/util/EventInterceptor.html
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?
Asked: 2009-12-12 01:05:21 +0800
Seen: 1,185 times
Last updated: Jan 01 '10