Event when closing Modal Dialog

1,840 views
Skip to first unread message

markus

unread,
Oct 6, 2012, 9:30:32 AM10/6/12
to wicket-j...@googlegroups.com
Hi Sebastien,

is there a notification call (onXXX) when closing the modal dialog with the upper-right-corner-(x) ?

Thanks
Markus



Sebastien Briquet

unread,
Oct 7, 2012, 7:19:24 AM10/7/12
to wicket-j...@googlegroups.com
Hi Markus,

Closing the dialog using the X-icon triggers the same jQuery 'close' (and 'beforeClose') event(s) than the 'close' method. So, there is no handler bound to this jQuery 'close' event because it would have resulted to a dual round-trip on button's click... (by default, buttons are closing the dialog).

Anyway, I added AbstractDialog#onConfigure(JQueryBehavior) (not yet committed), so you will be able to do something like this:
behavior.setOption("beforeClose", "function(event, ui) { if (event.button == 0 && !confirm('Are you sure you want to close?')) return false; }");

Hope this answers your question (I don't know your use case actually)...

Best regards,
Sebastien.

markus

unread,
Oct 7, 2012, 7:44:30 AM10/7/12
to wicket-j...@googlegroups.com
Hi Sebastien

sorry to didn´t make myself clear. I need the onClose because I need to do something like "cleaning the cage" stuff  (deleting a temp-directory,...)
So I wasn´t sure if it is a bug or a missing call because I expected the onclose-call as you described. I set breakpoints but neither the

    public void onEvent(IEvent<?> event)  {...} is called

nor the

    protected void onClose(AjaxRequestTarget target, DialogButton button)

method when closing the modal dialog with the (x).

Hmm - see my code  snippet below. I don´t think there is something wrong with it?
BR
Markus
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
...
        DialogAdd dialogAdd = new DialogAdd("dialogAdd", getString("dialog.add.title"))
        {
            @Override
            public void onSubmit(AjaxRequestTarget target)
            {
                // database.addEntry(....);
                info(getString("entry.added"));
                target.add(table);
                target.add(feedback);
            }

            @Override
            protected void onClose(AjaxRequestTarget target, DialogButton button)
            {
                System.out.println("onClose called");
            }

            @Override
            public void onEvent(IEvent<?> event)
            {
                super.onEvent(event);   
                System.out.println("Event called");
            }

            @Override
            protected List<DialogButton> getButtons()
            {
                return Arrays.asList(new DialogButton(getString("dialog.button.add")),
                                     new DialogButton(getString("dialog.button.cancel")));
            }

            @Override
            protected DialogButton getSubmitButton()
            {
                return this.findButton(getString("dialog.button.add"));
            }
        };
        add(dialogAdd);
.....




Sebastien Briquet

unread,
Oct 7, 2012, 8:22:09 AM10/7/12
to wicket-j...@googlegroups.com
Hi Markus,

#onClose() is only called either following a button's click (by default, of not overridden) or having manually invoked #close(ART, DialogButton).
No event is yet triggered after having clicked on the X-icon. That's by design, but it (the click on the X-icon) can still be handled to trigger an ajax event and then call #onClose.

In order for me to include this behavior - and as it will not be active by default - I need a proper property name that enables this behavior, like isXIconCloseEventEnabled().
If you find (or help me to find) a proper name, you will have this behavior by tonight :)

Also, please tell me which version of wicket-jquery-ui you are using (1.2.x or 6.0.x).

Best regards,
Sebastien

markus

unread,
Oct 7, 2012, 8:42:55 AM10/7/12
to wicket-j...@googlegroups.com
Hi Sebastien,

I´am not very good with finding names:) isStandardCloseWindowEventEnabled, isStandardCloseDialogEventEnabled , isDefaultCloseEventEnabled, ....

Do you really need to enable/disable the event?
Why not call a second function "onClose(AjaxRequestTarget target)" without a Dialogbutton


BTW:  is it possible to hide/suppress the x-icon? (may be it´s not a very good idea to solve the close event:)

BR
Markus

markus

unread,
Oct 7, 2012, 8:45:20 AM10/7/12
to wicket-j...@googlegroups.com
forgot... I am using wicket 6.x

Sebastien Briquet

unread,
Oct 7, 2012, 9:01:22 AM10/7/12
to wicket-j...@googlegroups.com
Hi Markus,

Yes, this specific event should *not* be enabled by default because I think that 90% of the use cases don't need an event to be triggered while clicking on this X-icon: we just want the dialog hides/closes without having a server round trip.
Thus, I think it is not possible to hide this X-icon, a least I did not saw an option that provides this capability.

I think I like the isDefaultCloseEventEnabled property name. I will use this name for now on, but I do not promise I will not change if I have a better idea afterwards! :)

It should be done by tonight, I will let you know.

Best regards,
Sebastien.

markus

unread,
Oct 7, 2012, 9:25:29 AM10/7/12
to wicket-j...@googlegroups.com
Hi Sebastien,
"better-afterwards-ideas" are always welcome:)
thx for your support 
Markus

Sebastien

unread,
Oct 7, 2012, 1:49:26 PM10/7/12
to wicket-j...@googlegroups.com
Hi Markus,

I just pushed the update on 'wicket6' branch.

To enable the "default close event", just override #isDefaultCloseEventEnabled() to return true.
Then, by clicking on the X-icon, the #onClose(AjaxRequestTarget, DialogButton) event will be triggered (DialogButton instance will be null).

Thanks to let me know if you encounter any issue.

Best regards,
Sebastien.

markus

unread,
Oct 7, 2012, 6:40:09 PM10/7/12
to wicket-j...@googlegroups.com
Hi Sebastien,
it works - great:)
Thx
Markus
Reply all
Reply to author
Forward
0 new messages