如何在 PageLoad 上打开 ModalDialog

发布于 2024-10-13 22:32:08 字数 124 浏览 2 评论 0原文

如何在 WebPage 的构造函数中,在没有 AjaxRequestTarget 的情况下,使用 Wicket 在 PageLoad() 上打开模式对话框?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苍白女子 2024-10-20 22:32:08

我找不到在没有 Ajax 请求的情况下打开它的方法,但完全可以在加载页面时打开它,只需一个简单的行为:

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>

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>
一个人的旅程 2024-10-20 22:32:08

在页面加载时打开模式窗口(不涉及 AJAX),如 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;
       }
}

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;
       }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文