Stop close modal window

asked 2014-07-18 07:23:56 +0800

sentinal gravatar image sentinal
11 2

updated 2014-07-18 07:24:16 +0800

I use viewModel in my app and i have closable window. When i click on close button in top-right of window command caused :


public void close(@BindingParam("win")Window win){

MessageBoxq.show("Are you sure want to close window?",....);

In method i have meesage box where i ask about close window. But when i click OK or CANCEL window close anyway. How to stop close window if i click CANCEL?

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-07-18 09:39:58 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

All you have to do is to stop propagation of the "close" event and then ask for a user confirmation using an event listener. Here is a complete example:

A simple main page:

<?page title="Main Page" contentType="text/html;charset=UTF-8"?>
<window title="Main Page" border="normal" 
        viewModel="@id('vm') @init('MainPageVM')">

    <button label="Open Modal Window" onClick="@command('open-modal-window')" />


and a view model:

public class MainPageVM {

    public void openModalWindow() {
        Executions.createComponents("modal-window.zul", null, null);        


And here is the modal dialog:

<?page title="Modal Window" contentType="text/html;charset=UTF-8"?>
<window id="winDialog"
        title="Modal Window" border="normal"
        width="400px" height="400px"
        viewModel="@id('vm') @init('ModalWindowVM')">

    <separator height="50px"></separator>
    <div align="center">
        Press the close button to return


And the view model:

public class ModalWindowVM {

  public void onClose(@SelectorParam("#winDialog") final Component window, 
              @ContextParam(ContextType.TRIGGER_EVENT) Event e) 
     Messagebox.show("Are you sure you want to close this window?", "Cancel", 
              new Messagebox.Button[]{Messagebox.Button.YES, Messagebox.Button.NO }, 
              new EventListener<Messagebox.ClickEvent>() {
            public void onEvent(ClickEvent event) throws Exception {
              if (Messagebox.Button.YES.equals( event.getButton() ))

Hope that helps


link publish delete flag offensive edit
Your answer
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

1 follower



Asked: 2014-07-18 07:23:56 +0800

Seen: 97 times

Last updated: Jul 18 '14

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