如何在页面加载上打开模态对话框

时间:2011-01-22 02:28:45

标签: java modal-dialog wicket

如何使用Wicket在PageLoad()的构造函数WebPageAjaxRequestTarget的构造函数中打开模式对话框?

2 个答案:

答案 0 :(得分:11)

在没有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>

答案 1 :(得分:1)

Wicket Wiki

中描述的页面加载(不涉及AJAX)上打开模态窗口
 /**
 * @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;
       }
}