我有一个这样的页面。
HTML
<form wicket:id="form" onsubmit="alert('form submit')">
<input type="text" name="name">
<!-- Wicket1.5.X form.onsubmit working -->
<!-- Wicket6.X form.onsubmit can not work -->
<input wicket:id="ajaxFallbackButton" type="submit">
<!-- form.onsubmit works fine -->
<input wicket:id="submitBtn" type="submit">
</form>
爪哇
Form<Void> form = new Form<Void>("form");
form.setOutputMarkupId(true);
add(form);
AjaxFallbackButton ajaxFallbackButton = new AjaxFallbackButton("ajaxFallbackButton", new Model<String>("AjaxFallbackButton"), form) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
System.out.println("ajaxFallbackButton onSubmit");
}
};
form.add(ajaxFallbackButton);
Button button = new Button("submitBtn", new Model<String>("Button"));
form.add(button);
为什么当我使用 Wicket V6.X 时,html中定义的onsubmit形式的事件无效?
感谢 svenmeier ,我通过覆盖AjaxFallbackButton.updateAjaxAttributes
方法修复了此问题。
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
AjaxCallListener ajaxCallListener = new AjaxCallListener();
ajaxCallListener.onPrecondition("alert('form submit')");
attributes.getAjaxCallListeners().add(ajaxCallListener);
}
答案 0 :(得分:0)
Wicket 6使用JavaScript事件处理程序,因此不会执行内联JavaScript。
请阅读此处以获得进一步的解释和解决方案: