Announcement Announcement Module
Collapse
No announcement yet.
How do I do a JQuery, Ajex call to a Spring Web Flow Event? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I do a JQuery, Ajex call to a Spring Web Flow Event?

    How can I I do a JQuery, Ajex call to a Spring Web Flow Event changing the eventId to 'loadSchools'?


    Here is my jquery code:
    Code:
        <script type="text/javascript">
            $(document).ready(function () {
                $("#borough").change(function() {
                    alert("Changed");
                    
                    
               });
            });
        </script>
    its not a lot of code its just waiting for a dropdown to be changed and then I need to kick off a event to spring webflow with the eventid of 'loadSchools'

  • #2
    you have to put in the request the parameter: _eventId=loadSchools
    you can do this simply adding them to your url: yourladdress?_eventId=loadSchools

    Comment


    • #3
      thanks.. I been trying the following code but its not working

      Code:
      <script type="text/javascript">
          $(document).ready(function () {
              $("#borough").change(function() {
                  $.post('${flowExecutionUrl}', {_eventId: 'loadSchools'}, function(){
                      alert('eventid was sent to url');
                  });
              });
          });
      </script>
      The issue is the above code works but I need to submit the rest of the form with it..
      Last edited by techsjs; May 28th, 2013, 09:54 AM.

      Comment


      • #4
        you understand that you are asking jquery help on a spring (webflow) forum?

        however I image you should find your form object with jquey, then serialize it and add the new vatriable before invoking the post:
        Code:
        var data = $('#myformid').serialize();
        data['_eventId'] = 'loadSchools';
        $.post('${flowExecutionUrl}', data, function(){
                        alert('eventid was sent to url');
                    });

        Comment


        • #5
          90% done but still not working

          I know I posted this into the springs forum the issue was the most jquery programmers only know PHP or perl and did not understant the eventID.


          your code did not work.. I had to do the following..

          Code:
          <script type="text/javascript">
              $(document).ready(function () {
                  $("#borough").change(function() {
          
                      $('input[name="_eventId"]').val('loadSchools');
          
                      var data = $('#member').serialize();
          
                      $.post('${flowExecutionUrl}', data, function(){
                          return true;
                      });
          
                  });
              });
          </script>
          Plus I had to add a hidden field..

          Code:
          <input type="hidden" name="_eventId"
                 value="${eventId}"/>
          but the issue is that I can see the controller is getting the flow now and is loading the data but its NOT loading the new JSP page

          Comment


          • #6
            I think you are a bit confused.. you expect an ajax call to refresh the page by itself? you are not doing anything with the response only returning true.
            If you want a full page refresh you should not use ajax just do a form submit
            Code:
            $('#member').submit();
            and in the form with id=member keep the hidden field
            Code:
            <input type="hidden" name="_eventId" value="${eventId}"/>

            Comment


            • #7
              no good

              I just updated the code and it does not do a submit

              Code:
              <script type="text/javascript">
                  $(document).ready(function () {
                      $("#borough").change(function() {
              
                          alert('Going to do the submit');
                          $('input[name="_eventId"]').val('loadSchools');
                          $('#member').submit();
                      });
                  });
              </script>
              The controller is NOT gettign called anymore

              Comment


              • #8
                I said keep the input field inside the form.. the code you have is creating an input field dynamically and not inside the form but at the end of the page, so is not posted with the form data and no event is fired.
                if you want to add the field dinamically to the form you have to do
                Code:
                $('input[name="_eventId"]').val('loadSchools').appendTo('#member');
                I suggest you also to add type as hidden or you'll have a normal input value and on slow browser/machine a use could see it appears just before submit.

                Comment


                • #9
                  no good

                  still not working.. I change the code to the following:
                  Code:
                  <script type="text/javascript">
                      $(document).ready(function () {
                          $("#borough").change(function() {
                              $('input[name="_eventId"]').val('loadSchools').appendTo('#member');
                              $('#member').submit();
                          });
                      });
                  </script>

                  Comment


                  • #10
                    what is this different from what I said?
                    hope is working for you now, bye

                    Comment


                    • #11
                      no I said this is NOT working

                      Comment


                      • #12
                        maybe because val() does not return the object?
                        try
                        Code:
                        var inp = $('input[name="_eventId"]').appendTo('#member');
                        inp.val('loadSchools');
                        //etc...

                        Comment


                        • #13
                          nooo

                          The following code did NOT work tooo

                          Code:
                          <script type="text/javascript">
                              $(document).ready(function () {
                                  $("#borough").change(function() {
                          
                          
                                      var inp = $('input[name="_eventId"]').appendTo('#member');
                                      inp.val('loadSchools');
                          
                                      $('#member').submit();
                                  });
                              });
                          </script>

                          Comment


                          • #14
                            it should be:
                            Code:
                                        var inp = $('<input name="_eventId" type="hidden">').appendTo('#member');
                                        inp.val('loadSchools');
                            sse this jsfiddle I made to test: http://jsfiddle.net/kcGCe/
                            apart from the message {"error": "Please use POST request"} because jsfiddle does not allow post data it works correctly for me(looking at the url invoked)

                            Comment

                            Working...
                            X