5 Replies Latest reply on Aug 30, 2010 6:50 AM by Rajendra J

    OnEnterkeyPress event call a java method and render the result in the same field

    Rajendra J Newbie

      hai guys,

       

      I have a form inside i have one text field, I entered date (24082010) and i will press enterkey; on-enterkeypress it will call a java bean method and pass the entered date to that method and process that date and result (22-Aug-2010)will rendered into same field; We have onblur event ajax support in rich faces; I have worked with that its working fine; But when i am using on enter key press it not at calling the particular java method; I am poor in java script so please anybody help me on this issue... I am waiting for your replies Its an urgent requirement for me please try to solve my problem.

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
         xmlns:ui="http://java.sun.com/jsf/facelets"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:a="http://richfaces.org/a4j"
         xmlns:rich="http://richfaces.org/rich">
      <head>
      <title>Hello</title>
      <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="otgstNam" ></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 for me can anyone please help me out....

        • 1. Re: OnEnterkeyPress event call a java method and render the result in the same field
          Ilya Shaikovsky Master

          do not make return at all in case when condition value means that request should be fired. any return true or false will prevent ajax call as it performed via js call and return before the call will abort it.

          • 2. Re: OnEnterkeyPress event call a java method and render the result in the same field
            Rajendra J Newbie

            Hi I am able to calling the java method by EnterKeypress and able to display the text into console;

            Now the problem is i am not able to render the result into JSF page; when im opening other browser then its displaying the formatted text;

            What is going over there??? Is reRender is not able to refreshing the page?? or reRender is not working correctly???


            Can i get the solution for this problem????

             

            Here i am pasting the code i am telling again that its calling java method but not able to display the formatted value into same text field

             

            Its purely facelets problem only; reRender is not working at all

             

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

             

            Can anybody get me the solution????

            • 3. Re: OnEnterkeyPress event call a java method and render the result in the same field
              Andreas Hoehmann Newbie

              Try a <a4j:form ajaxSubmit="true"... instead of  a <h:form...

              There is "strange" behavior with html / browser / forms with ONLY one inputfield ...

              Maybe your problem is the same I had some times ago ... I tried all combinations (IE, FF, form without field, with one field with two fields, ajax , none ajax ...) and at the end I found out ... there is something different for such forms ... I will write a blog about this (if i have some free time *g*) ...

              http://ahoehma.wordpress.com/2009/11/16/richfaces-modal-panel-default-formular-action/

              Regards

              Andreas

              1 of 1 people found this helpful
              • 4. Re: OnEnterkeyPress event call a java method and render the result in the same field
                Rajendra J Newbie

                Hi Andreas,


                First of all 'Thank you very much' for your help, I have struggled for 8 days and finally with your help I achieved it ;

                 

                The functionality that has been assigned for me was completed.

                 

                I have used that <a4j:form> instead of <h:form> as well as I have used <a:ajaxSubmit="true"> It works for me very well.

                 

                I never forget your help!!!! (Becoz its important and urgent for my requirement )

                 

                I have seen your link that was awesome for edit and cancel you have used that 'enter keys' and 'escape keys' that was good.

                 

                Anyways finally i got perfect solution, Thanks for everyone who helped me on this topic Especially Andreas and IIya .

                 

                Thanks to Rich faces forum

                 

                 

                Best regards

                Rajendra

                • 5. Re: OnEnterkeyPress event call a java method and render the result in the same field
                  Rajendra J Newbie

                  Hai guys,

                   

                  I have tried below code its working fine for me OnEnterKeypress. I suggest you to mind two things before using this event

                   

                  1. Use <a:form> instead if <h:form>

                  2.Use <a:form ajaxSubmit="true"> that it compulsory otherwise page will not Rerender formatted values into same field.

                   

                  Here is the code: Enjoy guys

                   

                  I would like to thank IIya and Andreas for their support. If anyqueries ask me through this discussion.

                   

                  <a:form id="mainForm" ajaxSubmit="true">
                               <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>
                          </a:form>