Created
March 11, 2017 03:07
-
-
Save kemsakurai/3ba1d1120572d284c2910454ada71122 to your computer and use it in GitHub Desktop.
StatelessAjaxPreventSubmitBehavior を作成しましたが、`AjaxCallListener` がStatefull のためStatelessにはならなかった。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.wicket.Component; | |
import org.apache.wicket.ajax.AjaxRequestTarget; | |
import org.apache.wicket.ajax.attributes.AjaxCallListener; | |
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes; | |
import org.apache.wicket.markup.html.form.TextField; | |
import org.apache.wicket.request.mapper.parameter.PageParameters; | |
import org.wicketstuff.stateless.behaviors.StatelessAjaxEventBehavior; | |
/** | |
* StatelessAjaxPreventSubmitBehavior | |
*/ | |
public class StatelessAjaxPreventSubmitBehavior extends StatelessAjaxEventBehavior { | |
/** | |
* Construct.. | |
*/ | |
public StatelessAjaxPreventSubmitBehavior() { | |
super("keydown"); | |
} | |
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { | |
super.updateAjaxAttributes(attributes); | |
Component component = this.getComponent(); | |
if (!(component instanceof TextField)) { | |
attributes.setChildSelector("input"); | |
} | |
AjaxCallListener listener = new AjaxCallListener(); | |
listener.onPrecondition("if (Wicket.Event.keyCode(attrs.event) === 13) {attrs.event.preventDefault();} return false;"); | |
attributes.getAjaxCallListeners().add(listener); | |
} | |
@Override | |
protected PageParameters getPageParameters() { | |
return null; | |
} | |
@Override | |
protected void onEvent(AjaxRequestTarget ajaxRequestTarget) { | |
ajaxRequestTarget.appendJavaScript("alert('test');"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
何か別の方法があるのかもしれません。