Wicket 设置窗口关闭回调不是在所有地方都可以吗?
我有一个模态窗口,里面有表单。用户可以通过两种方式关闭窗口:正确填写表单并提交更改,或单击右上角的“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要调用 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)