0

how to do onDetach?

asked 2009-06-26 16:46:25 +0800

james gravatar image james
255 2

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

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2009-06-30 02:42:17 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

try onOpen, and cast the event to OpenEvent, and read isOpen flag.

link publish delete flag offensive edit

answered 2011-10-27 11:06:51 +0800

digulla gravatar image digulla
506 5

Is this possible with ZK5?

We're registering lots of listeners in doAfterCompose() and we need to remove those when the composer is deleted.

link publish delete flag offensive edit

answered 2011-10-27 20:31:54 +0800

RichardL gravatar image RichardL
768 4

@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!");
        }
    }

link publish delete flag offensive edit

answered 2011-10-28 01:32:25 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

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

link publish delete flag offensive edit

answered 2011-10-28 06:39:32 +0800

nafiscrown gravatar image nafiscrown
21

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

link publish delete flag offensive edit

answered 2011-10-28 11:16:26 +0800

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

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.

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-06-26 16:46:25 +0800

Seen: 682 times

Last updated: Oct 28 '11

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