Form.onSubmit 中的模态窗口或确认框
在 Form.onSubmit 中,我可以向该表单添加 SimpleAttributeModifier 吗?实际上,我遇到的情况是,表单的 onSubmit 方法如下所示:
@Override
public void onSubmit() {
//some code
if (some_condition) {
//here I want to show Javascript confirm box or wicket modal window
//but I can not get any AjaxRequestTarget here to show that modal
add(new SimpleAttributeModifier("onSubmit", "return confirm('confirm msg')"));
}
//some code
}
它不起作用。有什么办法可以实现这一点吗?谢谢。
In Form.onSubmit can I add a SimpleAttributeModifier to that form? Actually I have a situation where the onSubmit method of the form look like this:
@Override
public void onSubmit() {
//some code
if (some_condition) {
//here I want to show Javascript confirm box or wicket modal window
//but I can not get any AjaxRequestTarget here to show that modal
add(new SimpleAttributeModifier("onSubmit", "return confirm('confirm msg')"));
}
//some code
}
It is not working. Is there any way to achieve this? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试的方法肯定行不通,因为
onSubmit()
方法没有及时调用。它是提交表单时调用的服务器端方法。为了显示确认对话框,您需要在表单从客户端发送回服务器之前在客户端执行一些 JavaScript。您需要在呈现 html 时附加 javascript,以便在用户单击提交按钮时调用它。
这当然可以做到。我没有自己的代码,但我认为这个例子 应该让你指向正确的方向。
What you're trying will definitely not work, as the
onSubmit()
method is not called in time. It is a server-side method called when the form is submitted. In order to show a confirm dialogue, you want some javascript executed on the client before the form is sent back from the client to the server.You need the attachment of javascript to happen when the html is rendered, so that it's there to be called when the user clicks the submit button.
It can of course be done. I don't have my own code for it handy, but I think this example should get you pointed in the right direction.