Automatic resizing of wickets ModalWindow

Martin Zellerjava, wicket 5 Comments

Today I ran into problems with wickets ModalWindow. I have got a modal dialog with a list and a form in it. The user can add a row to this list with the form. Problem was that the size of the modal window stayed as it was although the list was growing and growing. Nasty scroll bars appeared around my modal dialog. So I’d like to make the dialog to “auto resize” on each post.

My solution was simple. I just added this line of code in the onsubmit handler of the ajax button:

[java] // in the onsubmit handler of the ajax button
target.appendJavaScript("window.parent.Wicket.Window.current.autoSizeWindow();");
//[/java]

It’s like magic. Now the modal dialog always has the proper size 😉
(Tested with wicket version 1.5.5)

EDIT1: also have a look at Williams note below (the first comment)

EDIT2: also consider Nikkes solution!

Comments 5

  1. Very good information!. Still its important to note this will only work if your Modal has a Component that is a Panel, as if you are using a Panel Creator it will refize having a minimum size (nothing will be seen)

  2. Thanks Martin!

    Here is tiny modification that uses get() function in modal.js to get the current window instead of direct use of Wicket.Window.current that seems to work as well.

    target.appendJavaScript(“Wicket.Window.get().autoSizeWindow();”);

  3. Hey,

    Thanks for your post.

    I have a modal which vertical size is greater than the visible page, when i try to scroll, it scrolls down the page behind the modal page, got any ideas?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.