0

onClose event Window

asked 2006-04-18 17:31:06 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3692698

By: the-e-factory


Hi, it seems that the onClose event is not send to the window? Also the default behavior that the window gets detached isn't the case? or do did I missed something?
thanks
ps I use the ZK 1.2rc2: nice job!!

<?xml version="1.0" encoding="UTF-8"?>
<?page title="Test window"?>
<zk>

<window title="Test window" border="normal" id="win" > <button label="Make testwindow" onClick="makeTestWindow()"/>

<zscript>


public class TestWindow extends Window {

public TestWindow(){
makeLayout();
}

private void makeLayout() {

this.setTitle("testwindow");
this.setWidth("150px");
this.setHeight("150px");
this.setClosable(true);
this.setBorder("normal");

}
}
void makeTestWindow(){
Window testwindow = new TestWindow();
//testwindow.setId("testid");
testwindow.addEventListener("onClose", new EventListener(){

public void onEvent(Event e) {
//System.out.println(e.getName());
win.appendChild(new Label("labbel added"));
e.getTarget().setVisible(false);

}

public boolean isAsap() {
return true;
}

});
win.appendChild(testwindow);
}
</zscript>

</window>
</zk>




delete flag offensive retag edit

10 Replies

Sort by ยป oldest newest

answered 2006-04-19 06:18:27 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3693422

By: henrichen

There are two problems in your code:

1. Each event listener would be called if defined or added. I mean each of them.
While your onClose listener is called, the default onClose method defined in Window is also called (and detach the window). The programmer is supposed to call event.stopPropagation() to stop the event from propagate to the next event listener and stop right there. So, then add a event.stopPropagation() in your event listener...Here comes the second problem.

2. The event listener is called in a predefined sequence. The current sequence is 1)onXxx defined in zuml page 2) the onXxx method defined in java class 3) the dynamically added event listener into the component 4) the dyanmically added event listener into the page that the component belongs to. Add stopPropagation() in your code would not work since the onClose method defined in the window is already called.

I have propose a feature request to change the calling sequence
http://sourceforge.net/tracker/index.php?func=detail&aid=1472734&group_id=152762
&atid=785194

In the mean time, the work around is to define your onClose in Window as an Attribute (instead of an added event listener) and remember to call
event.stopPropagation() to stop the default Window onClose() method being called.

Still another workaround is to override onClose() method in your TestWindow class and the called event handling method would be your onClose() method.

/henri


link publish delete flag offensive edit

answered 2006-04-19 13:18:01 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3693961

By: the-e-factory


Hi, thanks for the good explanation !!

I changed the code, override the onClose method of the Testwindow class. I hope I did it the good way, but it seems that still the event is not processed ?.

<?xml version="1.0" encoding="UTF-8"?>
<?page title="Test window"?>
<zk>

<window title="Test window" border="normal" id="win" > <button label="Make testwindow" onClick="makeTestWindow()"/>

<zscript>


public class TestWindow extends Window {

public TestWindow(){
makeLayout();
}
public void onClose(){
//System.out.println("in the onclose method");
//this.appendChild(new Label("labbel added"));
//this.setVisible(false);
this.detach();
}

private void makeLayout() {

this.setTitle("testwindow");
this.setWidth("150px");
this.setHeight("150px");
this.setClosable(true);
this.setBorder("normal");

}
}
void makeTestWindow(){
Window testwindow = new TestWindow();
testwindow.setId("testid");
win.appendChild(testwindow);
}
</zscript>

</window>
</zk>



link publish delete flag offensive edit

answered 2006-04-20 01:49:27 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3695277

By: henrichen

I tried your example, it works for me. Try comment out the this.detach() in onClose(), the TestWindow would not disappear when click the close button. It proves that the onClose() in TestWindow was called and the onClose() in Window is NOT called.

Or add win.appendChild(new Label("close button clicked")); in your onClose(), you will see this label attached when you click the close button.

Note that you cannot try this example in our demo site which we forbidden new class definition for security reason.

/henri


link publish delete flag offensive edit

answered 2006-04-20 08:27:09 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3695600

By: the-e-factory

Yes, I noticed the same, but do you also have the Unique id issue when You push the makeTestwindow button again, after the window is detached. Normally the id gets relaesed from the IdSpace also when the window/component gets detached, so you can use the same id again ?
Thanks,
Eduard

link publish delete flag offensive edit

answered 2006-04-20 08:50:01 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3695624

By: henrichen

No, I don't have that "Unique" id issue. I can close it and push the button to create it again. No problem.

/henri

link publish delete flag offensive edit

answered 2006-04-20 10:14:45 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3695737

By: the-e-factory


Then I have a problem !! What could be the cause of my id issue: I use the 1.2rc2.

The fact is that it works also on my local installation of the zkdemo ?? (paste the code in a "Source" window and push try it) When I want to load the page from my appl I have this error. I use the same web.xml and zk.xml as the zkdemo (ofcourse changed the update-uri/auEngine to my appl), same tomcat, same libraries etc

Do you have an idee where my problem is located?
many thanks!!



link publish delete flag offensive edit

answered 2006-04-20 10:26:46 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3695754

By: the-e-factory


Hi,

I just use the zkdemo web.xml en zk.xml as they are for my appl, and this works, so can I asume that I don't have to change the udate-uri and auEngine to point out to my appl webroot ?
thanks

link publish delete flag offensive edit

answered 2006-04-20 11:14:02 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3695795

By: henrichen

Be honest, I have not idea why it is so. Something weird.

/henri

link publish delete flag offensive edit

answered 2006-04-20 11:28:05 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3695805

By: henrichen

Oh, the update-uri is neutral to your application root page. The browser need that uri to send correct pattern of Ajax url request to the DHtmlLayoutServlet (the servlet that handle the Ajax requests). There is no need to change that.

However, things is still strange if you simply change that uri and suffer the "unique id" issue. I will try here by changing that uri.

/henri

link publish delete flag offensive edit

answered 2006-04-20 11:39:26 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3695812

By: henrichen

Hi Eduard,

I have changed the update uri to /zkau1 and tried your example. It still works for me. Maybe you want to try the lastest nightly distribution? That is the version I tried on my PC.

/henri

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: 2006-04-18 17:31:06 +0800

Seen: 1,089 times

Last updated: Apr 20 '06

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