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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to