Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>AjaxBehaviorEvent</code> doesn't contain any information about the JavaScript <code>event</code> object. You need to pass the desired information along yourself. This can be achieved by a hidden input field whose value is to be prefilled by JavaScript. For example,</p> <pre class="lang-html prettyprint-override"><code>&lt;h:inputText value="#{bean.input}" onkeyup="document.getElementById('#{keyCode.clientId}').value=event.keyCode"&gt; &lt;f:ajax event="keyup" execute="@this keyCode" listener="#{bean.listener}" /&gt; &lt;/h:inputText&gt; &lt;h:inputHidden id="keyCode" binding="#{keyCode}" value="#{bean.keyCode}" /&gt; </code></pre> <p><em>(please note that the <code>id</code> of the hidden field is included in <code>execute</code> so that it get submitted along on the ajax request, please also note that the <code>binding</code> is used to be able to dynamically obtain the generated client ID in <code>document.getElementById()</code> in order to set the key code value, you could alternatively also hardcode the client ID if it's fixed)</em></p> <p>with</p> <pre><code>private String input; private int keyCode; public void listener() { switch (keyCode) { case 13: // Enter key was pressed. break; case 27: // Escape key was pressed. break; default: // Other key was pressed. break; } } </code></pre> <p>You can find an overview of all valid <code>keyCode</code> values in the <a href="https://developer.mozilla.org/en/DOM/event/UIEvent/KeyEvent" rel="noreferrer">Mozilla DOM reference</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload