2

How to use modifers like Ctrl or Shift with jsf.2.x and f:ajax (xmlns:f="http://java.sun.com/jsf/core")?

The code I have is

<h:graphicImage width="400" id="img02" style="background:blue;vertical-align:top"
        value="images/img?r=1#{Math.random()}" alt="not found">
           <f:ajax event="click" render="@this" listener="#{mBean.handleEvent}" />
</h:graphicImage>

and in the bean

public void handleEvent(AjaxBehaviorEvent event) {
  System.out.println("Debug event=" + event.toString());
  System.out.println(event.getComponent().getClientId());
}

But I have no idea how I can have a different behavior on ctrl-click and on simply click. Is it possible at all, and if, how can it be done?

EDIT2: now I have a working version that calls the setter and the listener:

<h:form id="vvv" class="small">
        <h:graphicImage width="500" id="img2c" 
            onclick="document.getElementById('#{ckeyX.clientId}').value=event.ctrlKey"
            value="images/img?y=#{Math.random()}">
            <f:ajax event="click" execute="@this ckeyX"
                listener="#{mBean.handleEvent}" render="@this">
            </f:ajax>
        </h:graphicImage>
        <h:inputHidden id="ckeyX" binding="#{ckeyX}" value="#{mBean.keyX}" />
    </h:form>

Must have had quite more than just one thick finger on my previous tries.

Gyro Gearloose
  • 1,056
  • 1
  • 9
  • 26
  • 1
    I know that PrimeFaces augmented some of its events to send modifier keys, but it actually needed to be done at the source. So you either have to change/override the javascript of the JSF impl you use, or do it like proposed by http://stackoverflow.com/questions/8652225/catch-keycode-in-ajaxbehaviorevent-of-jsf-2 So effectively this is a duplicate, right? – Kukeltje Dec 10 '15 at 09:11
  • @Kukeltje thanks, the link is a big step ahead. Still I don't see how this applies to clicks instead of keyboard events. – Gyro Gearloose Dec 10 '15 at 11:19
  • This was about passing it on. How to read it requies very little searching: http://stackoverflow.com/questions/2847135/check-ctrl-shift-alt-keys-on-click-event. How to set it: try using the onStart event of the ajax call and in there read the event and set a hidden input. Sorry, no time or urge to try and create a full answer, so if you do get it working, please create an answer. – Kukeltje Dec 10 '15 at 11:34
  • I'm new to nearly everything about this and right now I'm fighting to the setter of the input-filed (from your link) to work. Probably a dumb hidden error in my code or my (miss)understanding. Will be back when I see more clearly. – Gyro Gearloose Dec 10 '15 at 13:34
  • @Kukeltje: I just can't get it to work. Either there is some deep misunderstanding on my part or something is buggy. My problem even isn't in the original question but how to send an input form on click of my graphicImage, and worse, how to send any form when anything else is triggered. So this might be a duplicate or not, I can't tell until it works. At the very least, it's not an exact duplicate. – Gyro Gearloose Dec 12 '15 at 10:48
  • @Kukeltje now you may mark it a as duplicate – Gyro Gearloose Dec 16 '15 at 12:17

0 Answers0