0
votes

I have a Wicket page with multiple panels that allows the user to open a new Wicket page in a popup window. The user can enter some data, click submit in the popup and it closes after the submit has been processed.

How do I get a callback in the parent page that the popup has been closed so that I can refresh the parent page (the parent page needs to reflect the data the user entered in the popup)?

Is it possible to receive the callback in the panel of the parent page that was responsible for the popup opening so that I can only refresh the panel itself instead of the full page (this would require to also get the AjaxRequestTarget)?

3
If you use ModalWindow there is a callback on close. - Robert Niestroj

3 Answers

0
votes

I faced the same problem I resolved it using javascript to reload the parent page. I don't know if there is a better solution using wicket. But here is mine:

In the popup java file:

//...
Form<Void> form = new Form<Void>("form") {
  boolean close = false; // it says when the user has closed the window
  @Override protected void onSubmit() {
    //...
    close = true;
  }
  @Override public void renderHead(IHeaderResponse response) {
    super.renderHead(response);
    if(close) {
      // This javascript will close the file
      response.renderJavaScriptReference("js/close.js");
    }
  }
};

popup.js:

var _close = true;

And in the HTML of the popup:

    <script type="text/javascript">
       // if the var user is set and true it will reload the opener page and close itself
      function reload() {
        if(typeof _close != 'undefined' && _close) {                    
          window.opener.location.reload();
          self.close();
        }
      }
    </script>

The solution is quite messy (even the JS it's highly improvable), but it works :P For example, now I'd use JQuery, I'd my enclose the reload function inside $(document).ready(function() {...}); and I dont see no reason why dont put all the JS in the file (close.js) instead of spliting in the HTML and a separated file.

0
votes

1) You need to define Modal window in the parent page along with the dimensions you need to open it in.

2) Use setWindowClosedCallback(ModalWindow.WindowClosedCallback)(in the parent page) method and declare the piece of code inside this method which you want to after the modal closes. refer this for more info docs

Hope it helps.

0
votes

Check out the ModalX project in WicketStuff. It has "off the shelf" plumbing built in for all things modal, including a very simple IWindowCloseListener interface which you simply pass into your ModalX modal instance and it arranges for the correct callback, providing both the modal instance and an AjaxRequestTarget when the form is closed.