10 Replies Latest reply on Aug 30, 2010 8:19 AM by rajendra85

    Enter Key press Event on <a4j:support>

    rajendra85

      Click HELP for text formatting instructions. Then edit this text and check the preview.


      h:outputText value="Departure Date" id="otDepartureDate"></h:outputText>
      
      <h:inputText value="#{roomBooking.departureDat}" id="itdepDat" maxlength="8">
              <a:support event="onblur"
                         reRender="itdepDat" 
                         action="#{roomBooking.changeValue1}">
              </a:support>
      </h:inputText>



      I have used the above code for onblur event its working fine but we are not having any predefined event for EnterKeyPress so i have tried below code



      <html>
      <head>
      <script type="text/javascript" language="javascript">
      function dofocus(){
          var d = document.getElementById("mainForm:itdate");
          d.focus();
      }
      </script>
      </head>
      
      <body>
          <f:view>
              <h:form id="mainForm">
                 <h:outputText value="Name" id="otdate" ></h:outputText>
                     <h:inputText value="#{user.dateEntered}" id="itdate" onfocus="true" >
                      <a:support event="onkeyup"
                            onsubmit="if (window.event.which == 9 || window.event.which == 13)
                                      {return true;} return false;"
                               action="#{user.changeValue}"
                               reRender="itdate" />
                      </h:inputText>   
              </h:form>
          </f:view>
      </body>
      </html>





      Its not working can anybody; get me the actual solution..



      Im repeating the question


      Q: I have a form; inside a i have only one text field; I have entered some date like(22092010) after i press enter then a java method should call and process the text and return the result(22-Sep-2010) back to the same text field.


      shortly: call a java method via javascript i.e;


      after hitting an event that is OnEnterKeypress


      Thanks in advance


        • 1. Re: Enter Key press Event on <a4j:support>
          boy18nj

          It seems your onsubmit javascript code has syntax problem, write the same code as a javascript function like function dofocus() and then call that function.

          • 2. Re: Enter Key press Event on <a4j:support>
            rajendra85
            Click HELP for text formatting instructions. Then edit this text and check the preview.

            hi
            `<html>
            <head>
            <title>Hello</title>
            <script type="text/javascript" language="javascript">
            function chk(ev) {
            var key;
            ev = ev || event;
            if (ev.keyCode == 13 || ev.which==13) {
            var val = document.getElementById("mainForm:textfield").value;
            alert ("You pressed the Enter key\nYou have entered " + val);
            }
            }
            </script>
            </head>
            <body>
              <f:view>
                <h:form id="mainForm">
                    <h:outputText id = "otfield" value="Enter date"/>
                    <h:inputText id = "textfield" size = "20" onkeypress = "chk(event)">
                    <a:support event="onkeypress"
                               action="#{user.changeValue}"
                               reRender="textfield"
                               id="okp">
                    </a:support>
                   </h:inputText>
                </h:form>
              </f:view>
            </body>
            </html>`

            Hi guys,

            I have tried the above code for normal java script function and Im getting Alert message
            so I can able to get the enterKeypress event but Im not able to get the ajax function call...

            function chk(ev) : will work fine but Im unable to call the java method; it is not working can anybody know how to call action method after enterkeypress event..can anybody get me the code...?


            Please its an urgent requirement for me

            Thanks in advance..

            ""

            • 3. Re: Enter Key press Event on <a4j:support>
              raphaufrj
              • 4. Re: Enter Key press Event on <a4j:support>
                rajendra85

                Click HELP for text formatting instructions. Then edit this text and check the preview.


                I got the solution i tried this code its working fine its calling the java method after enter key press and able to display the formatted text in the console; but i am not able to render the formatted text into the JSF page; when close the browser and opens again i am able to get the formatted text into the text field I think the JSF page is not refreshing;Its not able to reRender the value into the JSF page


                Can anybody help me in this.
                Can anybody help me in this.


                and I am pasting the code that i have used!!!!Its working as metioned above.....




                <body>     
                <f:view>
                <h:form id="mainForm">
                  <h:inputText value="#{user.dateEntered}" id="t1">
                    <a:support      event="onkeyup" 
                           action="#{user.changeValue}"
                           onsubmit="if (event.keyCode != 13) { return false; }" 
                           reRender="t1" />
                   </h:inputText>
                  </h:form>
                </f:view>
                </body>



                 

                • 5. Re: Enter Key press Event on <a4j:support>
                  rajendra85

                  Click HELP for text formatting instructions. Then edit this text and check the preview.


                  I have got the solution for this topic can anybody struggle on this plaese see the below link I have attached code;


                  My Link

                  • 6. Re: Enter Key press Event on <a4j:support>
                    rajendra85

                    Rajendra J wrote on Aug 30, 2010 08:14:


                    Click HELP for text formatting instructions. Then edit this text and check the preview.

                    I have got the solution for this topic can anybody struggle on this plaese see the below link I have attached code;  Click on : MyLink

                    My Link


                    Click HELP for text formatting instructions. Then edit this text and check the preview.

                    • 7. Re: Enter Key press Event on <a4j:support>
                      rajendra85


                      I have got the solution for this topic can anybody struggle on this plaese see the below link I have attached code;  Click on : MyLink


                      My Link



                      • 8. Re: Enter Key press Event on <a4j:support>
                        rajendra85

                        Rajendra J wrote on Aug 30, 2010 08:16:




                        I have got the solution for this topic can anybody struggle on this plaese see the below link I have attached code;  Click on : MyLink

                        Finally those who responded this topic or issue I am thankful to everyone.

                        My Link





                        Click HELP for text formatting instructions. Then edit this text and check the preview.

                        • 9. Re: Enter Key press Event on <a4j:support>
                          rajendra85

                          I have got the solution for this topic can anybody struggle on this plaese see the below link I have attached code;  Click on : MyLink


                          My Link



                          Finally those who responded this topic or issue I am thankful to everyone.

                          • 10. Re: Enter Key press Event on <a4j:support>
                            rajendra85