On 8/3/06, p.jasson < [EMAIL PROTECTED]> wrote:
I have a markup container with AjaxEvenBehavior for 'onclick'.
In the onEvent method i need to know whether CTRL was pressed during the
click or no.
How can it be done?


If you need to know it on the server you have to change the request url on the AJAX request to add some parameters for it. Something like this perhaps:


package wicket.sandbox.pages;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import wicket.Request;
import wicket.RequestCycle;
import wicket.ajax.AjaxEventBehavior;
import wicket.ajax.AjaxRequestTarget;

/**
 * AJAX Behavior which returns the client side click information to the server. You get information like
 * is CTRL/ALT/SHIFT key pressed and x and y of the mouse position.
 *
 * @author Frank Bille (billen)
 */
public abstract class ClickBehavior extends AjaxEventBehavior {

    public ClickBehavior() {
        super("onclick");
    }   

    protected CharSequence getCallbackScript(CharSequence partialCall, CharSequence onSuccessScript, CharSequence onFailureScript) {
        String superCallbackScript = super.getCallbackScript(partialCall, onSuccessScript, onFailureScript).toString();
       
        Pattern pat = Pattern.compile("^wicketAjaxGet\\('([^']+)'$");
        Matcher mat = pat.matcher(partialCall);
       
        if (mat.matches()) {
            StringBuffer url = "" StringBuffer(mat.group(1));
           
            // CtrlClick
            url.append ("&");
            url.append("ctrlKey='+event.ctrlKey+'");
            url.append("&");
            url.append("altKey='+event.altKey+'");
            url.append ("&");
            url.append("shiftKey='+event.shiftKey+'");
            url.append("&");
            url.append("xPos='+event.clientX+'");
            url.append ("&");
            url.append("yPos='+event.clientY+'");
           
            superCallbackScript = superCallbackScript.replace(mat.group(1), url.toString());
        }
       
        return superCallbackScript;
    }

    protected final void onEvent(AjaxRequestTarget target) {
        Request request = RequestCycle.get().getRequest();
       
        boolean ck = Boolean.parseBoolean (request.getParameter("ctrlKey"));
        boolean ak = Boolean.parseBoolean(request.getParameter("altKey"));
        boolean sk = Boolean.parseBoolean(request.getParameter("shiftKey"));
        int x = Integer.parseInt(request.getParameter("xPos"));
        int y = Integer.parseInt(request.getParameter("yPos"));
       
        onEvent(target, new ClickEvent(ck, ak, sk, x, y));
    }

    protected abstract void onEvent(AjaxRequestTarget target, ClickEvent event);
   
    public static class ClickEvent {
        private boolean ctrlKey;
       
        private boolean altKey;
       
        private boolean shiftKey;
       
        private int x;
       
        private int y;
       
        public ClickEvent(boolean ctrlKey, boolean altKey, boolean shiftKey, int x, int y) {
            this.ctrlKey = ctrlKey;
            this.altKey = altKey;
            this.shiftKey = shiftKey;
            this.x = x;
            this.y = y;
        }

        public boolean isAltKey() {
            return altKey;
        }

        public boolean isCtrlKey() {
            return ctrlKey;
        }

        public boolean isShiftKey() {
            return shiftKey;
        }

        public int getX() {
            return x;
        }

        public int getY() {
            return y;
        }
    }
}



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to