Wicket 设置窗口关闭回调不是在所有地方都可以吗?

发布于 2024-12-17 02:10:19 字数 2191 浏览 0 评论 0原文

我有一个模态窗口,里面有表单。用户可以通过两种方式关闭窗口:正确填写表单并提交更改,或单击右上角的“x”。

现在我正在尝试做以下事情:

当用户成功填写表单并提交更改时,在父页面上我尝试显示(使用 jQuery)一些有关成功的信息。

当用户单击“x”时,我希望关闭模式窗口而不需要任何附加信息。但是 setWindowClosedCallback 没有按我的预期工作。看看我的代码,首先我引用了 modalWindow (我省略了代码中一些不有趣的部分,例如添加表单输入等):

public EditEmailForm( String id, final ModalWindow modalWindow,final User u )
{
    super( id );
    modalWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() 
    {
    private static final long serialVersionUID = 1L;

    @Override
    public void onClose(AjaxRequestTarget target) 
    {
            //here some code doing jQuery magic for parent page
    }
});
    AjaxSubmitLink closeBtn = new AjaxCloseCancelBtn( "close-x", this );

    add( new AjaxSubmitLink( "save", this )
    {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit( AjaxRequestTarget target, Form<?> form )
        {
        //here's user info change
        }

        @Override
        protected void onError( AjaxRequestTarget target, Form<?> form )
        {
            target.add( feedbackPanel );
        }
    } );
    add( closeBtn );
}


protected class AjaxCloseCancelBtn extends AjaxSubmitLink
{
    private static final long serialVersionUID = 1L;

    public AjaxCloseCancelBtn( String id, Form<?> form )
    {
        super( id, form );
        setDefaultFormProcessing( false );
    }

    @Override
    protected void onSubmit( AjaxRequestTarget target, Form<?> form )
    {
        modalWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() 
        {
            private static final long serialVersionUID = 1L;

            @Override
            public void onClose( AjaxRequestTarget arg0 )
            {               
            }

        });
        // revert fields values
        form.clearInput();
        // close popup
        modalWindow.close( target );
    }

    @Override
    protected void onError( AjaxRequestTarget target, Form<?> form )
    {
    }

}

此代码工作 50%,因为它在父页面上显示了我想要的内容,但当我点击“x”时,即使我试图设置新的窗口关闭回调(它是空的),它也会这样做。有什么解决方案可以克服这个问题吗?

I have a modal window with form inside it. There are two way user can close the window: either by filling up correctly form and submit change, or clicking an "x" in top right corner.

Now I'm trying to do following thing:

When user sucesfully fills up the form and submit change, on parent page I'm trying to display (with jQuery) some information about success.

When user clicks an "x" I want the modal window to be closed without any additional info. However setWindowClosedCallback is not working as I expected. Take a look at my code, first I'm getting reference to modalWindow (I omitted some not interesting parts of the code like adding form inputs etc.):

public EditEmailForm( String id, final ModalWindow modalWindow,final User u )
{
    super( id );
    modalWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() 
    {
    private static final long serialVersionUID = 1L;

    @Override
    public void onClose(AjaxRequestTarget target) 
    {
            //here some code doing jQuery magic for parent page
    }
});
    AjaxSubmitLink closeBtn = new AjaxCloseCancelBtn( "close-x", this );

    add( new AjaxSubmitLink( "save", this )
    {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit( AjaxRequestTarget target, Form<?> form )
        {
        //here's user info change
        }

        @Override
        protected void onError( AjaxRequestTarget target, Form<?> form )
        {
            target.add( feedbackPanel );
        }
    } );
    add( closeBtn );
}


protected class AjaxCloseCancelBtn extends AjaxSubmitLink
{
    private static final long serialVersionUID = 1L;

    public AjaxCloseCancelBtn( String id, Form<?> form )
    {
        super( id, form );
        setDefaultFormProcessing( false );
    }

    @Override
    protected void onSubmit( AjaxRequestTarget target, Form<?> form )
    {
        modalWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() 
        {
            private static final long serialVersionUID = 1L;

            @Override
            public void onClose( AjaxRequestTarget arg0 )
            {               
            }

        });
        // revert fields values
        form.clearInput();
        // close popup
        modalWindow.close( target );
    }

    @Override
    protected void onError( AjaxRequestTarget target, Form<?> form )
    {
    }

}

This code works 50% good, as it displays what I want on parent page, but it also does it when I hit an "x" even tho I'm trying to set new window close callback which is empty. Any solution how can I overcome this?

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

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

发布评论

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

评论(1

夏日落 2024-12-24 02:10:19

您需要调用 org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.close(AjaxRequestTarget)

You need to call org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.close(AjaxRequestTarget)

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