JSF 2.0 ajax : Submit form  on Enter key press in h:inputTextarea

Dear All,
I am new to JSF 2.0 . Just wanted to submit the form in ajax when a user hits the "Enter": key while typing
in the h:inputTextarea . I would be very thankful to you guys if you help me out.
Thanking in advance!

I found the problem and a solution :-) The missing piece of the puzzle was the id attribute for the form tag. After some debugging of the JSF JavaScript I found the solution.
The JavaScript function response(request, context) is invoked to handle the server response. Inside this function the doUpdate(element, context) is invoked.
The doUpdate() function is doing the modification of the DOM. The function doUpdate() is two times invoked for a response. The first time the html elements are updated.
The second time the view state hidden field is updated or created but only under the following condition:
Comment in the JavaScript source code of the jsf.js
//Now set the view state from the server into the DOM
//but only for the form that submitted the request.If the forms of the both side haven't the same id the form can't be found on the second page.
In the following way it is working:
page1.xhtml
<h:form id="myform">
        <h:commandLink value="Go to page 2" action="page2">
            <f:ajax render="@all" execute="@all"/>
        </h:commandLink>
</h:form>
.....page2.xhtml
<h:form id="myform">
            <h:commandLink value="Go to page 1" action="page1">
                <f:ajax render="@all" execute="@all"/>
            </h:commandLink>
</h:form>So always set an explicit id for each JSF tag.

Similar Messages

  • Capture enter key press in h:inputtext

    hi,
    i have a h:inputText component in my jsf page. i need to capture the enter key pressed for this component. how can this be done.
    thanks in advance.

    You can use Javascript for this. In the onkeypress event, check if the keycode is 13 (the enter key) and handle accordingly.
    onkeypress="if (event.keyCode == 13) alert('Enter pressed!');"

  • Submitting form with Enter key

    Hello,
    in standard html form, when you have form with submit button, the enter key when any form element is selected submits the form.
    This is very convenient for users, so I want this with UIX forms. I know it is possible (I have one form where it is working), but I can't get it working anywhere else.
    This code works:
    <uix:form method="post" name="newRoleForm">
    <uix:inlineMessage prompt="Role name">
    <uix:textInput name="newRoleName" />
    <uix:spacer width="15" />
    <uix:submitButton text="Create" formName="newRoleForm" />
    </uix:inlineMessage>
    <uix:formValue name="jboEvent" value="newRole" />
    </uix:form>
    When I copy this code to another page, it does not work...
    Can somebody help, please?

    I've studied the HTML generated by UIX and it has following bugs and misfeatures:
    1. Misfeature: Submitting with Enter works ONLY if there is exactly one text field in the form (no submit button is actually needed), as Brian Stoler wrote. I don't understand reason for this.
    2. Bug: UIX generates javascript function "_submitOnEnter" which is called as event handler for "onKeyPress" event. But this function is erroneously generated multiple times, once for each form in the page. Browsers (Mozilla and IE) use the latest implementation. This function is different for forms with one text field and for forms with more text field, but only the first one can do the job. As a consequence of this, Enter can submit the form only if the last form on a page has single text field (which is for example not the case of search form with single field above another form...)
    Tested with UIX 2.1.7 in JDeveloper 9.0.3.3, using UIX as JSP tag library.
    Workaround:
    1. Use Opera browser: it submits form with enter key even if there is no submit button (this does not work for the first text field in the form, because it has "onkeypress" event handler).
    2. Implement this feature by hand yourself, if you really need it (see below).
    3. Use accessKey: allows to submit form with Alt+<key> combination (followed by Enter with IE).
    Implementing Enter key submits with Javascript:
    1. Put the following function to the header (or to javascript library):
    function enter(e, frm) {
    var kc;
    if(window.event) kc=window.event.keyCode;
    else if(e) kc=e.which;
    else return true;
    if(kc==13) {
    submitForm(frm,1);
    return false;
    Function copied from UIX (C).
    2. Add this event handler to each input element:
    onKeyPress="return enter(event, 'formName');"
    It is obvious that this is error prone, but it works with all browsers...
    Will this be fixed in future versions?
    Why only form with one text field can be submitted?

  • Capturing Enter Key Press

    Hi
      Is there a way where we can capture the Enter Key press of the Keyboard and call an event on the Enter Key Press??
    For fields such as input field there is onEnter field where an event can be called, but we have a requirement where in we need to call an event on click of enter key, irrespective of where the focus on the page is on.
    Any inpus on this will be helpful.
    Thanks & Regards,
    Gayathri Shanbhag

    Hi Gayathri,
    See if the following link helps:
    https://cw.sdn.sap.com/cw/docs/DOC-107045
    Regards,
    Himanshu

  • Submitting a form with enter key causing strange problems

    I am having a very strange problem with a webapp I am currently developing. I am using JSF 1.2 along with Facelets and RichFaces. I have coded a workflow/wizard 4-step process, and on some pages I have 4 submit buttons that all call different actions on the page. The users thought it would be useful to have the enter key submit the form, so I followed some online resources to trap a keypress using javascript, looking for the enter keycode and calling document.getElementById("elementName").click(). This works fine most of the time. Sometimes, though, it seems as if an entire new session is being created, and odd behavior starts happening. For example, my page will only include 2 of the 4 facelets on the screen -or- I will get NullPointerExceptions for objects that I know have been created in the session bean I am currently using -or- I will get a duplicate form Id after trying to re-submit the page. Could the javascript click simulation not be submitting all of the form elements or is the enter key also acting like its default action (the form submission) in addition to the "click"? I'm really at my wit's end here (plus it's nearly 3 AM, that never helps things). All of the buttons being clicked are standard h:commandButtons. There is some setTimeout logic included to disable the buttons on the page to prevent double clicks (I cannot disable them onsubmit because disabled buttons don't pass the right values, perhaps that's causing it, but if so, clicking the buttons with the mouse would cause that issue too, right?)
    I am not posting the code (yet), but if anyone wants to take a look see and see if I am doing something really abhorrently wrong, I'm more than willing to, I'm just curious if anyone has had problems regarding javascript submission of forms via the click() method. Clicking the button does not exhibit this type of behavior. Just as a side note: I am doing different things with the enter key depending if a modal window is open (the enter key closes the modal if it's up, and if not, it submits the form via a button click).
    Any help is much appreciated, if anyone has any inkling about where I should start looking for answers it would be really helpful.
    Thank you.

    edfrost wrote:
    Could the javascript click simulation not be submitting all of the form elements or is the enter key also acting like its default action (the form submission) in addition to the "click"?My guess is the second of these. You need to suppress the event handling after programmatically clicking the button.

  • CF7 - sending a form using "Enter" key

    As I wrote in the subject, i've goit a question.
    How can I send a form using the "Enter" key. When I push the
    Enter nothing happneds. Can someone help me?

    OK. My mistake. In normal HTMLform there is no problem.
    I've got the Flash form
    [code]
    <cfform name="register" format="Flash" skin="haloBlue"
    width="300" height="200" timeout="999999999"
    action="index.html">
    <cfinput type="hidden" name="skrypt" value="#skrypt#">
    <cfinput type="hidden" name="save" value="True">
    <cfinput type="Text" name="username"
    label="Użytkownik: " required="Yes" message="Proszę
    podać użytkownika" size="20">
    <cfinput type="Password" name="pass" label="Hasło: "
    required="Yes" message="Proszę podać hasło"
    size="20">
    <cfinput type="submit" name="submit" value="Loguj">
    </cfform>
    [/code]

  • Enter key press instead of tab key

    I want to use enter key Instead of tab key in my page to move to next item
    Please answer in detail steps because i am new to apex and especially to Javascript

    I strongly advice against using an app like this.
    I always play by the rule not to re-invent the wheel.
    Try to convince the user from the new possibilities and the fact that tabbing is a default procedure.
    You'll see that this will be easier than actually programming the enter-key to act like the TAB key.
    I you really need to do this, then you'll need to do something like this
    http://thinksimply.com/blog/jquery-enter-tab
    good luck!
    Regards,
    Richard
    blog: http://blog.warp11.nl
    twitter: @rhjmartens
    If this question is answered, please mark the thread as closed and assign points where earned..

  • Configuring what element gets enter key press in JDialog?

    Hi all,
    In windows applications, some dialogs or windows, have a specific button that gets activated when enter is pressed. E.g. in a JDialog, the OK button would normally be activated when no button had focus. How do you set this to be? Is there some API call to do this? And is there some way to do the same with the escape key, so that cancel will always get triggered when its pressed?
    I just don't want to have to manually add a key listener to each component in the dialog that listens for the escape and enter buttons to be pressed.
    thanks,
    J

    As for the Esc key, there is nothing "out of the box" to do this. I created a JDialog sub-class to handle it, which I use in place of JDialog throughout my app. In the JDialog sub-class, over-ride the createRootPane() method as follows:
        * Overriding this method to register an action so the 'Esc' key will dismiss
        * the dialog.
        * @return a <code>JRootPane</code> with the appropiate action registered
       protected JRootPane createRootPane()
          JRootPane pane = super.createRootPane();
          pane.getInputMap( JComponent.WHEN_IN_FOCUSED_WINDOW ).
             put( KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), "escPressed" );
          pane.getActionMap().put( "escPressed",
             new AbstractAction( "escPressed" )
                public void actionPerformed( ActionEvent actionEvent )
                   onDialogClose();
          return pane;
       }then, create an abstract onDialogClose() method like the following:
        * This method gets called when the user attemps to close the JDialog via the
        * 'Esc' key.  It is up to the sub-class to implement this method and handle
        * the situation appropriately.
       protected abstract void onDialogClose();Alternatively, you could create a default implemenation of onDialogClose() instead of making it abstract; sub-classes could still over-ride it if they needed custom behavior.
    HTH,
    Jamie

  • Setting component to recieve enter key presses?

    Hi all,
    if I have a dialog with a number of buttons on it, is there anyway I can set one component (an OK button) to be activated when the enter button is pressed, and another one (cancel) to be activated when the escape button is pressed?
    I know I could add actions to the action map, but isn't there usually a way to set one button to be actived on enter. It usually appears in bold, or slightly highlighted.
    thanks,
    J

    Hi all,
    if I have a dialog with a number of buttons on it, is
    there anyway I can set one component (an OK button)
    to be activated when the enter button is pressed, and
    another one (cancel) to be activated when the escape
    button is pressed?
    I know I could add actions to the action map, but
    isn't there usually a way to set one button to be
    actived on enter. It usually appears in bold, or
    slightly highlighted.
    someDialog.getRootPane().setDefaultButton(someButton);Jim S.

  • Hitting Enter Key thru java code

    I am executing telnet commands through java code. The problem is after executing the commands and giving exit command telnet asks to press any key to come to normal prompt.
    How can we pass "ENTER KEY pressed" through java code. so that i should not wait for the user to press the enter key.

    Hello rajureddy and dboyd68
    Thanks for yours suggestions, I resolved the problem thanks to example that was pointed by dboyd68.
    Instead to fire event onkeypress on BODY tag I have passed call on FORM tag, and it works fine.
    Thanks again.

  • Enter key instead of TAB key

    Hi folks,
    I'd like to make the ENTER key behave the same way as the TAB key in
    the system I'm developing. I thought I would be able to do it by setting
    the ENTER as a function key (using Window.SetAsFunctionKey), and
    then after detecting an ENTER key press, request focus on the current
    fieldwidget's 'NextTabField'. However, this attribute defaults to NIL unless
    you override the default TAB sequence. And I don't really fancy setting
    the Next and Prev TabField for every onscreen field.
    Anyone done this before using a simpler method?
    By the way, I don't really want to get into a long thread about whether it is
    good practice to bypass Windows (TM) standards or not. We require
    fast data entry, and keyboard entry is essential for that.
    Cheers,
    Duncan Kinnear,
    McCarthy and Associates, Email: [email protected]
    PO Box 764, McLean Towers, Phone: +64 6 834 3360
    Shakespeare Road, Napier, New Zealand. Fax: +64 6 834 3369
    Providing Integrated Software to the Meat Processing Industry for over 10 years
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Duncan,
    The application we are building will replace legacy application and had similar
    requirements to accommodate the current users. We solved this problem by creating a
    special frame, appropriately named as the "Terminal Frame". It is distributed as
    part of the Scaffolds framework.
    The Terminal frame implements ENTER instead of TAB key. As you know the tabbing
    order in a terminal frame (top to bottom, left to right) is different than windows
    tabbing order (left to right, top to bottom). The Terminal frame solves the tabbing
    problem by constructing a "field traverse list" which includes all the fields in a
    window including nested views ordered according to their X,Y co-ordinates. It is a
    recursive method works on the same lines as described by Sakharov, Nickolay in
    earlier mail. The method also sets the NextTabField, PrevTabField references for
    each field in the traverse list.
    This framework is working very well for us. In a terminal frame world, you still
    have some user training issues as some of the fields (OutlineField, DropList,
    ArrayField, CheckBoxe etc.) behave differently for ENTER and TAB keys. But these
    are minimal compared to a complete change in style.
    Hope this is helpful.
    Good Luck,
    Shirish
    Duncan Kinnear wrote:
    On 22 Jun 99, at 23:47, Jeanne Hesler wrote:
    Do the math on this one. Be sure your users understand the cost and the
    lack of payback. I have no problem going against common practice when
    there is a good reason, but this reason just doesn't add up. Even if it
    did slow them down, which it won't, they would never lose enough time to be
    worth the work that it would take to implement.Jeanne,
    Thanks for your reply (even though it doesn't help me!).
    Don't get me wrong, I'm not advocating we abandon the TAB key
    functionality in favour of the ENTER key. I just want to ADD the ENTER
    key as a navigational aid for our 'legacy' users (and we have many). If it
    is done right, there should be no need to tell the user about it. Their
    transition to the new product would be virtually painless.
    Since I posted my original question I've realised that the cost of
    implementation is actually fairly low. And this is why. I have just
    discovered that the default tab order defined by Forte (left to right, top to
    bottom) is essentially useless for most of the windows we will be creating.
    Therefore, we will need to override it by explicitly setting the
    "NextTabField" and "PrevTabField" attributes of our input fields in virtually
    every window. As I am writing the framework for our new product, I will
    have to implement the facility to do this in the framework itself. And if we
    have our tab order defined, then adding the ENTER key functionality is
    minimal extra effort (see my original post). In fact, if I implement it in my
    "CoreWindow" (the root of my windows framework inheritence tree), then
    no-one will ever have to deal with it again.
    The TAB key is not even much of a windows data-entry standard. Many
    of our customers have defined secondary systems using Microsoft
    Access, and it uses the ENTER key (along with the TAB key) to move
    from field to field. Will these customers not complain that they cannot
    use the ENTER key to move between fields if we don't implement it?
    As we do not have the resources to completely rewrite our existing
    COBOL system (over 2 million lines of code) in one go. We will be rolling
    out the new system module by module. This means that a lot of our users
    will be switching between the new windows interface and the text-based
    unix telnet sessions. When I switch back and forth between windows
    editors and 'vi' on the unix host, I experience first-hand how mixed
    navigational facilities can hamper productivity!
    Anyway, I was just hoping there might be a little setting somewhere in
    Forte to switch this on, but as no-one has pointed it out, it seems unlikely.
    Thanks again for your input, lively discussion is always welcome.
    Cheers,
    Duncan Kinnear,
    McCarthy and Associates, Email: [email protected]
    PO Box 764, McLean Towers, Phone: +64 6 834 3360
    Shakespeare Road, Napier, New Zealand. Fax: +64 6 834 3369
    Providing Integrated Software to the Meat Processing Industry for over 10 years
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>--
    Shirish Kulkarni <mailto:[email protected]>
    Sage IT Partners <http://www.sageitpartners.com>
    44 Montgomery St. Suite 3200 San Francisco, CA 94104
    (925)210-6965 Office (415) 399-7001 Fax
    The Leaders in Internet Enabled Enterprise Computing
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

  • Use Enter key to execute report.

    I have a report that needs to be executed in background.It has a selection screen.The program should get executed when user presses 'ENTER' while he is inside the selection screen.At present,when 'ENTER' key is pressed,only validation is done.To execute we are  either pressing 'F8'  key or click execute button in screen.
    Now how to trap the 'ENTER' key press in  a report?

    Hi Jayaprakash,
    All PAI processing will depend on the Function Code that has been triggered at the selection screen.
    The ENTER key has no function code, whereas the "Execute" button has the function code 'ONLI'. SO what can be done is, when the user hits the ENTER key, we can programmatically set the function code to 'ONLI'. I shall give you a very small peice of code to illustrate my point.
    ===================================
    tables sscrfields.
    parameters p_vblen like vbak-vbeln obligatory.
    at selection-screen.
    if sscrfields-ucomm eq space.
    sscrfields-ucomm = 'ONLI'.
    endif.
    start-of-selection.
    write p_vblen.
    ===================================
    The above code will trigger the report output on hitting the ENTER key at the selection screen.
    What you only have to note here is that unlike with screen processing, in selection-screen processing, the function code will be made available in the field UCOMM of the structure SSCRFIELDS. However, you will have to declare this structure in your program ( using the TABLES statement as shown above ).
    Hope the explanation has been clear enough to drive the point home for you. Please get back to me otherwise.
    Regards,
    Anand Mandalika.

  • Problem with disabling "ENTER" key in JTextArea

    Hi,
    I have the following codes to disable the 'ENTER' key in the JTextArea,
    but it does not work. Does anyone know why?
    KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    textarea.getKeymap().removeKeyStrokeBinding(enterKey);
    textarea.addKeyListener(new KeyAdapter() {
    public void keyTyped(KeyEvent e) {
    // do something
    Thanks,
    Pin

    I don't know how you mean "disable", but if you are going to ignore the Enter key, then add a KeyListener to the text area, and in the key pressed method, consume() the key event if the VK_ENTER was pressed. That's all, and you don't have to deal with that key binding thingy.
    The other two event types (typed and released) might be ignored, the enter is processed during key press (as it is now, with the default settings).
    The reason is that processing the Enter key (and other such internally understood keys) is done by the peer, but the peer won't get the key event if it's already consumed.
    FYI: Were it a JTextField, consuming the Enter key presses would mean that the field won't fire action events any more. Since text area does not fire action events, therefore it's a non issue.
    FYI2: Consuming the event only blocks the event to be sent to the peer, all the other listeners still get it.

  • Repeat last command with enter key in dbx

    I am using dbx 7.7 on Solaris 10 (Sun Studio 12.1). Is it possible to configure dbx so that pressing the <enter> key will always repeat the previos command? for instance, if i do one "next" command, i want consequent <enter> key-presses to do "next", until i explicitly execute a different command.
    Thanks,
    Yael

    yaelfrommer wrote:
    Hello Jean,
    Thanks for this advice, i started working with dbxtool and it's very nice.
    2 questions:
    1. The Function keys (F7, F8, etc.) don't work, any idea what could be the problem?There is a bug in the dbx cmdio window where it ignores F-key. It doesn't even have
    a decent context menu. You should be able to get F7 etc working by moving the
    focus elsewhere, like the editor window.
    2. In the default .dbxrc file there's a line "button ignore step up" to "add `step up' button to GUI", but no button was added. Is there anything else i should do to make this work?
    These are really old. (we should remove them from the default .dbxrc!)
    The current way to add a button is via Debug->NewDbxButton
    Thanks,
    Yael

  • Blue "Change" button does not respond to enter key (OS X)

    After entering a new Time in the "Edit Capture Time" screen you select change and the new time is applied. This could be done by selecting the "change" button with the mouse or by hitting the return key or the enter key (since "change" is the blue highlighted button). But in Lightroom 3 and now in Lightroom 4B the enter key doesn't work. Can you please fix this bug. Thanks!

    Just to be sure, I updated the program as follows. Click on the mouse to request focus and then hit enter key.
    Click on the mouse prints the String "enter key pressed". Then press the Enter key..no action activated.
    var button : SwingButton;
    Stage {
    title: "MyApp"
    visible: true
    scene: Scene {
    width: 100
    height: 100
    content: [
    button = SwingButton {
    text: "Button"
    action: function() {
    println("enter key pressed");
    button.requestFocus();
    onKeyPressed : function(event : KeyEvent):Void
    println("enter key pressed");
    }

Maybe you are looking for

  • Calendar can the day's number be displayed?

    A day is displayed with the usual information - the day of the week and the date, and month.   Is it possible to have the number of the day as it relates to the entire year displayed?  For example - October 30, 2013 is day 303/365.  Is this feature a

  • Drill Back from HFM works for one year, not another

    Hello, We are on FDM and HFM 11.1.2.1 and I was doing some reasearch in the system today and for some reason in all periods that were loaded during 2011 in this version (Aug-Dec) I am able to drill back to the FDM source data. However, if I go into 2

  • Correct image rotation with CameraRoll

    At the moment I'm implementing CameraRoll in my app. It's a great class, but the images do not rotate correctly on Android. Other apps seem to be able to determine if the picture was taken in landscape or portrait mode, and view the image in the corr

  • Top 10 Queries in Database...

    Hello Guys, My boss wants to know the database queries ran in last 10 days. What is the best way to get this informatiom. He also wants to know the top 10 heavy quries that took the most cpu resources and time. We have database 10g release 2 and OEM

  • How do I transfer itunes library from old computer to new one?

    How do I transfer my old itunes library to my new computer?