Child pages
  • Modal Windows
Skip to end of metadata
Go to start of metadata

Adding scrollbars to a modal window

In your WebPage:

...

add(new BookmarkablePageLink("myLink", MyPopupPage.class, params).setPopupSettings(PopupSettings.SCROLLBARS));

...

Refreshing page when a modal window is closed

In your WebPage:

modalWindow.setWindowClosedCallback(new WindowClosedCallback(){
	private static final long serialVersionUID = 1L;

	@Override
	public void onClose(AjaxRequestTarget target){
		target.addComponent(parentPage);
	}
});

An alternative approach would be to do it on the client side:

public class MyPopupCloseLink extends PopupCloseLink {
	@Override
	protected void onComponentTag(ComponentTag tag) {
		super.onComponentTag(tag);
		tag.put("onclick", "window.parent.refresh();");
	}
}

Opening a modal window on page load (no AJAX involved)

If you need to open up a modal window when a page is loaded following extension of ModalWindow class will do the trick.

/**
 * @author Ernesto Reinaldo Barreiro 
 */
public class OpenOnLoadModalWindow extends ModalWindow implements
IHeaderContributor {

       private static final long serialVersionUID = 1L;

       /**
        * @param id
        */
       public OpenOnLoadModalWindow(String id) {
               super(id);
       }

       /**
        * @param id
        * @param model
        */
       public OpenOnLoadModalWindow(String id, IModel<?> model) {
               super(id, model);
       }

       /**
        * Adds the JavaScript to initially open modal window.
        */
       public void renderHead(IHeaderResponse response)
       {
               response.renderOnDomReadyJavascript(getWindowOpenJavascript());
       }

       /*
        * (non-Javadoc)
        * @see org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow#makeContentVisible()
        */
       @Override
       protected boolean makeContentVisible()
       {
               return true;
       }
}

The trick boils down to do two things:

-Making sure the contents of the modal window are visible on initial rendering (makeContentVisible())
-Making sure the JavaScript opening the modal window is executed when page is loaded.

// TODO : Add other examples

  • No labels