title: ZK: Refreshing parent window while closing child window
body: <p>I want to implement in ZK to refresh a parent window while closing its child window.</p>
  
  <p>Parent.zul - This has a dropdown and a button (label as add to dropdown) to add value to this drop down. when this button clicked, it should open a child winow with an option to enter text to the dropdown. </p>
  
  <p>child.zul : this has a text box to enter value for the dropdown and a "CLOSE" button. when the close button is clicked, it should close the child window and refresh the dropdown in the parent window. </p>
  
  <p>Thanks in advance for your input.</p>
  
  <p>==========================================================================</p>
  
  <p>Parent: sock.zul</p>
  
  <pre><code>&lt;window id="sockWindow" title="New Sock" width="600px" apply="SockController" mode="modal" closable="true"&gt;
      &lt;div align="left" style="float: left;" &gt;    
          &lt;button id="btnLookup" label="Manage Lookup" width="150px"/&gt;
      &lt;/div&gt;    
  &lt;/window&gt;
  </code></pre>
  
  <p>sockController.java:
  public class SockController extends SelectorComposer  {</p>
  
  <pre><code>@Listen("onClick = button#btnLookup")
  public void onClickAdd() throws Exception {
      showPopup(new EventListener&lt;Event&gt;() {
          @Override
          public void onEvent(final Event event) throws Exception {
              Object someData = event.getData(); // cast to whatever object you expect to give.   
              //Make your refresh code here.                
          }
      });          
  
  }   
  
  public static void showPopup(final EventListener&lt;Event&gt; eventListener)
      throws InterruptedException {
  //you can give more params with the method to add them as arguments.
      Map arguments = new HashMap&lt;String, String&gt;();
      arguments.put("source", "parent.zul");
    //  arguments.put("hid", hwid.toString());
    //  arguments.put("displaymode", displaymode);
  
      openModal("/managelookup.zul",null, arguments, eventListener);
  }
  
  public static void openModal(final String page, final Component parent,
      final Map&lt;String, Object&gt; obMap,
      final EventListener&lt;Event&gt; onCloseListener)
      throws InterruptedException {
      for (final Map.Entry&lt;String, Object&gt; entry : obMap.entrySet()) {
          Executions.getCurrent().setAttribute(entry.getKey(),
              entry.getValue());
      }
      Executions.getCurrent().setAttribute(Composition.PARENT, null);
      final Component createComponents = Executions.createComponents(page,
              parent, obMap);
      Component parent1 = createComponents;
      parent1 = getWindow(parent1);
      if (parent1 instanceof Window) {
          final Window window = (Window) parent1;
          if (onCloseListener != null) {
              //attach the listener so when popup is closed the listener is called.
              window.addEventListener(Events.ON_CLOSE, onCloseListener);
              window.addEventListener(Events.ON_CANCEL, onCloseListener);
          }
          window.doModal();
      }
  }  
  </code></pre>
  
  <p>}</p>
  
  <p>child : managelookup.zul:
  
      </p>
  
  <pre><code>        &lt;button id="cancel" label="Close"/&gt;
  &lt;/window&gt;
  </code></pre>
  
  <p></p>
  
  <p>ManageLookupsController.java:
  public ManageLookupsController() throws Exception{</p>
  
  <pre><code>@Listen("onClick = button#cancel")
  public void onClickCancel() {
  
      manageLookup.setVisible(false);
      manageLookup.detach();
      Events.postEvent(Events.ON_CLOSE, windowOrSpaceOwner, someData);
  }    
  </code></pre>
  
  <p>}</p>