ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

Problem with nested oppup windows

ajaidka
2 Sep 2011 23:27:18 GMT
2 Sep 2011 23:27:18 GMT

I am facing problem with nested popup windows. When I do an escape on child, onCancel of parent is called, hence both windows get closed.
I just want to close child first and on 2nd escape parent should be closed.

this is how i am creating popup windows.
Window popupWin = (Window) Executions.getCurrent().createComponents("edit_product_options_group_popup.zul", self, arg);
popupWin.doModal();

Any idea??

jimmyshiau
5 Sep 2011 20:15:40 GMT
5 Sep 2011 20:15:40 GMT

Hi ajaidka,
can you provide a reproducing sample?

ajaidka
6 Sep 2011 02:54:04 GMT
6 Sep 2011 02:54:04 GMT

index.zul

<?page title="Auto Generated index.zul"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<window title="Hello World!!" border="normal" width="200px" apply="com.test.popup.MainCtrl">
<button id="openPopup" label="Open Popup"></button>
</window>

MainCtrl.java
public class MainCtrl extends GenericForwardComposer {

private Button openPopup;

public void setOpenPopup(Button openPopup) {
this.openPopup = openPopup;
openPopup.addEventListener("onClick", new EventListener() {

@Override
public void onEvent(Event arg0) throws Exception {
Window popupWin = (Window) Executions.getCurrent().createComponents("/popup_win.zul", self, arg);
try {
popupWin.doModal();
} catch (SuspendNotAllowedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}


}

popup_win.zul
<?page title="First Popup" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="Parent Popup" border="normal" apply="com.test.popup.PopupWinViewCtrl" onCancel="self.detach();">
New Content Here!

<button id="openChildPopup" label="Open Child Popup"></button>

</window>
</zk>


PopupWinViewCtrl .java
public class PopupWinViewCtrl extends GenericForwardComposer {

private Button openChildPopup;

public void setOpenChildPopup(Button openChildPopup) {
this.openChildPopup = openChildPopup;

openChildPopup.addEventListener("onClick", new EventListener() {

@Override
public void onEvent(Event arg0) throws Exception {
Window popupWin = (Window) Executions.getCurrent().createComponents("/child_popup_win.zul", self, arg);
try {
popupWin.doModal();
} catch (SuspendNotAllowedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});

}

}

child_popup_win.zul
<?page title="First Popup" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="Parent Popup" border="normal" closable="true" onCancel="self.detach();">
Press Escape!
</window>
</zk>


escape on child_popup_win will close it's parent too.

ajaidka
7 Sep 2011 14:14:35 GMT
7 Sep 2011 14:14:35 GMT

Can I just avoid window to be closed when I do Escape?

Aashu

jimmyshiau
14 Sep 2011 03:37:37 GMT
14 Sep 2011 03:37:37 GMT

I have tested the following sample with ZK 5.0.7.1
it works fine

<zk>
	<window title="Win 1" border="normal" width="200px" mode="modal" onCancel="System.out.println(1);self.detach();">
			<window title="Win 2" border="normal"  mode="modal"  onCancel="System.out.println(2);self.detach();">
				<textbox/>
			</window>
		<textbox/>
	</window>
</zk>