模态窗口中的Wicket AjaxLink不起作用

时间:2015-07-22 10:02:14

标签: java ajax wicket

我正在尝试在ModalWindow中添加AjaxLink。这个AjaxLink用于执行一些操作,例如从数据库中删除某些内容,最后关闭ModalWindow

我根据Wicket示例Link to examples添加了ModalWindow。但这不起作用。

我的主页:

    public class EventPanel extends Panel {
            // some stuff happens here, the constructor accepts the eventModel
            final ModalWindow modal;
            add(modal = new ModalWindow("modal"));
            modal.setCookieName("modal-1");

            modal.setPageCreator(new ModalWindow.PageCreator() {
                public Page createPage() {
                    // Use this constructor to pass a reference of this page.
                    return new DeleteEventWindow(eventModel, modal);
                }
            });

            modal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {
                public boolean onCloseButtonClicked(AjaxRequestTarget target) {
                    // Change the passValue variable when modal window is closed.

                    return true;
                }
            });

            // Add the link that opens the modal window.
            add(new AjaxLink<Void>("showModalLink") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    modal.show(target);
                }
            });
      }

模态窗口:

    public class DeleteEventWindow extends WebPage {

           public DeleteEventWindow(final IModel<Event> model,
                                    final ModalWindow window) {

              // some stuff happens

              // this link doesn´t work
              add(new AjaxLink<Void>("closeOK") {
                  @Override
                  public void onClick(AjaxRequestTarget target) {
                 // Just a print to console for debugging
                  System.out.println("nooo");
                  window.close(target);
               }
        });

    }
  }

ModalWindow HTML

   <html>
          <head>
              <title>Modal Content Page</title>
          </head>
   <body>
    <!-- some other fields output --!>
    <a wicket:id="closeOK">close</a><br/>
   </body>
   </html>

ModalWindow本身工作正常,链接也会呈现。但如果我点击它,似乎没有触发onClick函数。我也试过了正常Link,这很好..

我也发现了这个问题:stackoverflow question,但我使用的是JQuery 1.9.1 ..

1 个答案:

答案 0 :(得分:0)

您的代码没有提供足够的信息;你有一个模态窗口添加到一个项目(我假设的行项目),但显示模态的链接被添加到面板。