-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I am creating a modal window and I want something to happen when the window detaches.. I've tried onClose, but that event isn't triggered if I do win.detach(). There is no "win.onDetach()" and no "win.close()". so does anyone have any ideas of how I can run some code when the window detaches? or how to get the "onClose()" event to trigger when i do win.detach()?
Thanks for any advice I can get.
-James
try onOpen, and cast the event to OpenEvent, and read isOpen flag.
@Dennis This doesn't seem to work with win.detach().
public void onOpen$win(Event event) throws InterruptedException, Exception { OpenEvent e = (OpenEvent) event; if (e.isOpen()) { alert("isOpen!"); } else { alert("isClosed!"); } }
Looks like I have a wrong suggestion 2 years ago..
onOpen is sent when user clicked the close button at the right corner of the window. it wan't send by server operation.
I don't know what kind of listeners you are adding. you could look UiLifeCycle listener, it works as a listener when a component is attached or detached.
noticed that, it will call to the root component that was detach/attached. you have to dig in if you has many composers deeply inside the component
Hi,
Pls see this code
<window id="win">
<button label="Ok">
<attribute name="onClick">
Window win = Executions.create("/modelwin.zul",null,null);
win.addForwardEvent("onDetach",win,"onCustomEvent");
</attribute>
</button>
<attribute name="onCustomEvent">
alert("Hi");
</attribute>
</window>
i hope this code helps you.
Regards
Nafis
The above code won't work because there is no such event as onDetach.
I recommend using the approach dennis mentioned (UiLifeCycle). It's a bit tricky to get right because it's a per-application listener and you'll have to traverse component trees manually to achieve what you are trying to do.
If you can read Scala code, you can get some ideas from my implementation:
LifeCycleHooks.scala
My implementation enables a programmer to do this:
val button = new Button LifeCycleHooks.onComponentAttach(button, () => { // This code is run when button is attached from the page }) LifeCycleHooks.onComponentDetach(button, () => { // This code is run when button is detached from the page })
The basic idea is that hook functions are saved as component attributes. When the UiLifeCycle mechanism detects a detached component, the component and all it's descendants are searched for hook functions and those functions are executed.
Asked: 2009-06-26 16:46:25 +0800
Seen: 682 times
Last updated: Oct 28 '11