You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Malte <ma...@googlemail.com> on 2013/01/23 21:41:30 UTC
AjaxEventBehavior that catch only some keypresses
Hi!
I want write an AjaxEventBehavior that calls the server if an function
key is pressed. Im also need to know on serverside which key is
pressed.
I'd tried it with this code:
public HomePage(final PageParameters parameters) {
super(parameters);
add(new AjaxEventBehavior("keydown"){
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes
attributes) {
super.updateAjaxAttributes(attributes);
IAjaxCallListener listener = new AjaxCallListener(){
@Override
public CharSequence getPrecondition(Component component) {
//this javascript code evaluates wether an
//ajaxcall is necessary.
//Here only by keyocdes for F9 and F10
return "var keycode =
Wicket.Event.keyCode(attrs.event);" +
"if ((keycode == 120) || (keycode == 121))" +
" return true;" +
"else" +
" return false;";
}
};
attributes.getAjaxCallListeners().add(listener);
//Append the pressed keycode to the ajaxrequest
attributes.getDynamicExtraParameters()
.add("var eventKeycode =
Wicket.Event.keyCode(attrs.event);" +
"return {keycode: eventKeycode};");
}
@Override
protected void onEvent(AjaxRequestTarget target) {
//Extract the keycode parameter from RequestCycle
final Request request = RequestCycle.get().getRequest();
final String jsKeycode = request.getRequestParameters()
.getParameterValue("keycode").toString("");
target.appendJavaScript("alert('from wicket ajax. you
pressed "+jsKeycode+"')");
}
});
My Problem is, that this blocking all Inputevents on all Inputfields
on the page. I find out, that the result false in the
Preconditionscript cause in a stopping of Eventhandling.
What can I do, that only the keys 120 and 121 result in an
ajaxcallback and leave all other keyevents untouched?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: AjaxEventBehavior that catch only some keypresses
Posted by Sven Meier <sv...@meiers.net>.
attributes.allowDefault(true)
Sven
On 01/23/2013 09:41 PM, Malte wrote:
> Hi!
>
> I want write an AjaxEventBehavior that calls the server if an function
> key is pressed. Im also need to know on serverside which key is
> pressed.
>
> I'd tried it with this code:
> public HomePage(final PageParameters parameters) {
> super(parameters);
>
> add(new AjaxEventBehavior("keydown"){
> @Override
> protected void updateAjaxAttributes(AjaxRequestAttributes
> attributes) {
> super.updateAjaxAttributes(attributes);
>
> IAjaxCallListener listener = new AjaxCallListener(){
> @Override
> public CharSequence getPrecondition(Component
> component) {
> //this javascript code evaluates wether an
> //ajaxcall is necessary.
> //Here only by keyocdes for F9 and F10
> return "var keycode =
> Wicket.Event.keyCode(attrs.event);" +
> "if ((keycode == 120) || (keycode == 121))" +
> " return true;" +
> "else" +
> " return false;";
> }
> };
> attributes.getAjaxCallListeners().add(listener);
>
> //Append the pressed keycode to the ajaxrequest
> attributes.getDynamicExtraParameters()
> .add("var eventKeycode =
> Wicket.Event.keyCode(attrs.event);" +
> "return {keycode: eventKeycode};");
> }
>
> @Override
> protected void onEvent(AjaxRequestTarget target) {
> //Extract the keycode parameter from RequestCycle
> final Request request = RequestCycle.get().getRequest();
> final String jsKeycode = request.getRequestParameters()
> .getParameterValue("keycode").toString("");
>
> target.appendJavaScript("alert('from wicket ajax. you
> pressed "+jsKeycode+"')");
> }
>
> });
>
> My Problem is, that this blocking all Inputevents on all Inputfields
> on the page. I find out, that the result false in the
> Preconditionscript cause in a stopping of Eventhandling.
>
> What can I do, that only the keys 120 and 121 result in an
> ajaxcallback and leave all other keyevents untouched?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org