Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open ModalDialog on PageLoad

How can I open a modal dialog on PageLoad(), in the constructor of the WebPage and without the AjaxRequestTarget, with Wicket?

like image 790
sonjafon Avatar asked Jan 22 '11 02:01

sonjafon


People also ask

How do you show modal dialog?

The Window. showModalDialog() created and displayed a modal dialog box containing a specified HTML document.

Can you trigger a modal with a link?

Just replace "Your link text" with what you want the link to say, and paste the modified modal trigger link into your website. Unlike the JavaScript for your modal form, you should paste the modified modal trigger link where you want it to appear on your website. NOTE: Modal trigger links are now each their own link.


2 Answers

I couldn't find a way to open it without an Ajax request, but it's perfectly possible to open it when the page is loaded, with a simple behavior:

HomePage.java

public class HomePage extends WebPage {
    public HomePage(PageParameters pageParameters) {
        super(pageParameters);

        ModalWindow modal = new ModalWindow("modal");
        modal.add(new OpenWindowOnLoadBehavior());
        modal.setPageCreator(new ModalWindow.PageCreator() {
            @Override
            public Page createPage() {
                return new RedirectPage("http://www.google.com");
            }
        });
        add(modal);
    }
}

OpenWindowOnLoadBehavior.java

public class OpenWindowOnLoadBehavior extends AbstractDefaultAjaxBehavior {
    @Override
    protected void respond(AjaxRequestTarget target) {
        ModalWindow window = (ModalWindow) getComponent();
        window.show(target);
    }
    @Override
    public void renderHead(IHeaderResponse response) {
        response.renderOnLoadJavascript(getCallbackScript().toString());
    }
}

HomePage.html

<html xmlns:wicket="http://wicket.apache.org">
<body>
  <div wicket:id="modal"></div>
</body>
</html>
like image 100
tetsuo Avatar answered Sep 30 '22 01:09

tetsuo


Opening a modal window on page load (no AJAX involved) described in Wicket Wiki

 /**
 * @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;
       }
}
like image 37
row Avatar answered Sep 30 '22 03:09

row