Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7023473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:42:56+00:00 2026-05-27T23:42:56+00:00

I have a JSF ajax keyup event linked to an event listner in a

  • 0

I have a JSF ajax keyup event linked to an event listner in a backing bean.

The code in the JSF file is like below.

<h:inputText id="txtDescription" value="#{institutionController.current.description}" disabled="#{institutionController.modifyControlDisable}" >
    <f:ajax event="keyup" listener="#{institutionController.changeDetailsEvent}" />
</h:inputText>

The code in the backing bean is like below.

public void changeDetailsEvent(AjaxBehaviorEvent event) {
}

I want to achieve different logic depending on the key presses, like shown is pseudocode below.

public void changeDetailsEvent(AjaxBehaviorEvent event) {
    If (event.key = Key.enter) {
        do something;
    } else if (event.key = Key.Escape) {
        so something else;
    } else {
        do nothing;
    }

}

Can someone please tell me how this is done in the backing bean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:42:56+00:00Added an answer on May 27, 2026 at 11:42 pm

    The AjaxBehaviorEvent doesn’t contain any information about the JavaScript event 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,

    <h:inputText value="#{bean.input}" onkeyup="document.getElementById('#{keyCode.clientId}').value=event.keyCode">
        <f:ajax event="keyup" execute="@this keyCode" listener="#{bean.listener}" />
    </h:inputText>
    <h:inputHidden id="keyCode" binding="#{keyCode}" value="#{bean.keyCode}" />
    

    (please note that the id of the hidden field is included in execute so that it get submitted along on the ajax request, please also note that the binding is used to be able to dynamically obtain the generated client ID in document.getElementById() in order to set the key code value, you could alternatively also hardcode the client ID if it’s fixed)

    with

    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;
        }
    }
    

    You can find an overview of all valid keyCode values in the Mozilla DOM reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have JSF code like: <h:inputText id=from value=#{fromToMBean.fromName}/> I would like to get this
I have the jsf code and css code below. I'm having trouble getting the
I have a basic JSF page called Index.xhtml and a backing bean called TestBean.java.
Is there a way to have a JSF Backing bean cause an update of
I have an ajax execute-tag embedded in a commandLink-Tag in my JSF-File, which works
I have a JSF data table <h:dataTable id=memberTable value=#{bean.pList} border=0 rowClasses=rowEven rowOdd var=item> <h:column
I have a JSF application that uses mostly Richfaces. I would like to introduce
I would like to have a central place where I monitor ajax requests and
I have some jQuery code that runs on every $(document).ready() event. I also have
I have a problem with using jQuery Dialog and Ajax submit in JSF. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.