10 Replies Latest reply on Feb 11, 2010 7:42 AM by Janine Graul

    Seam Remoting - Getting values!

    Roger Lee Apprentice
      I’ve got Seam Remoting calling my EJB’s methods from a JS function;

      function loadDirections() {
      var devicesToTrackBean = Seam.Component.getInstance("devicesToTrackBean");
            var size = devicesToTrackBean.getPiNPOiNTsListSize();
            alert('size = ' + size);
      }

      and the in the envelope in the debug window is correct. There are 17 entities in my list.

      Sun Jan 31 19:31:07 UTC 2010: Response packet:
      <envelope><header><context><conversationId>17</conversationId></context></header><body><result id="0"><value><number>17</number></value><refs></refs></result></body></envelope>

      However the alert just says ¨size = [object]’

      I can’t see how I can get the value out of the ¨envelope’.

      What I really want to do is call the EJB method which returns a list of objects and put them into an array in my JS function.

      Any pointers?

      Thanks


        • 1. Re: Seam Remoting - Getting values!
          Shane Bryzak Master

          The A in AJAX stands for asynchronous.  You need to define a callback method to receive the result of your invocation:




          function loadDirectionsCallback(result) {
            alert('size = ' + result);
          }
          
          function loadDirections() {
            var devicesToTrackBean = Seam.Component.getInstance("devicesToTrackBean");
            devicesToTrackBean.getPiNPOiNTsListSize(loadDirectionsCallback); 
          }



          • 2. Re: Seam Remoting - Getting values!
            Roger Lee Apprentice

            Sorted. Many thanks.

            • 3. Re: Seam Remoting - Getting values!
              Roger Lee Apprentice

              Shane,


              I am still having trouble getting a list of Objects back into an array. Whilst Googling I came across this post;


              http://seamframework.org/Community/SeamRemotingAndEvaluatingELExpressions


              Is this still the case? I'm using Seam 2.2.0.GA.


              Thanks

              • 4. Re: Seam Remoting - Getting values!
                Shane Bryzak Master

                The eval feature is still disabled, but based on the code you pasted you're not using it anyway.  What sort of trouble are you having exactly?  It might help to post some code.

                • 5. Re: Seam Remoting - Getting values!
                  Roger Lee Apprentice
                  EJB passes back a list of DevicesToTrack entities;


                  @WebRemote
                  List getPiNPOiNTsList();


                  public List getPiNPOiNTsList() {       
                      log.info("***** getPiNPOiNTsList pinPointsList = " + this.pinPointsList.size())       
                      return this.pinPointsList;
                  }


                  The JavaScript Alert displays the size of the list/array correctly;

                  <script type="text/javascript">
                         
                  function loadDirections() {
                      var devicesToTrackBean = Seam.Component.getInstance("devicesToTrackBean");         
                      devicesToTrackBean.getPiNPOiNTsList(loadDirectionsCallback);
                  }

                  function loadDirectionsCallback(result) {
                      var piNPOiNTsList = result;
                      alert('loadDirections = ' + piNPOiNTsList.length);
                  }
                  </script>

                  However if I add a for loop in the JS to display the contents of the array;

                  function loadDirectionsCallback(result) {       
                      var piNPOiNTsList = result;
                      alert('loadDirections = ' + piNPOiNTsList.length);
                     
                      for (var i = 0; i < piNPOiNTsList.length; i++) {       
                          alert("piNPOiNTsList: " + piNPOiNTsList[i]);
                      }
                  }

                  I get;

                  Error Parsing /map.xhtml: Error Traced[line: 39] The content of elements must consist of well-formed character data or markup.

                  Can't see for the life of me what's wrong with JS?
                  • 6. Re: Seam Remoting - Getting values!
                    Roger Lee Apprentice
                    ¨Error Parsing /map.xhtml: Error Traced[line: 39] The content of elements must consist of well-formed character data or markup.¨

                    Solved - Replaced < with &lt;

                    But unable to access the data from the array of entities.
                    • 7. Re: Seam Remoting - Getting values!
                      Shane Bryzak Master

                      Are you importing the JavaScript type stubs for the objects contained in the List?  Also, why are you assigning the result param to a local variable? There's no need, just use the param directly.

                      • 8. Re: Seam Remoting - Getting values!
                        Janine Graul Newbie

                        I have exactly the same problem.
                        Has somebody found a solution by now?

                        • 9. Re: Seam Remoting - Getting values!
                          Roger Lee Apprentice
                          What is your problem?

                          I got it working by converting my List to an Array and passing that back to the JavaScript function.

                          <script language="JavaScript" type="text/javascript">

                               window.onload = initialize;
                               function initialize() {
                                      var devicesToTrackBean = Seam.Component.getInstance("devicesToTrackBean");
                                      devicesToTrackBean.getDevicesToTrackCurrentLocation();
                                     
                                      loadDirections();
                                  }

                                  function loadDirections() {
                                      var devicesToTrackBean = Seam.Component.getInstance("devicesToTrackBean");
                                       devicesToTrackBean.getPiNPOiNTsListAsArray(loadDirectionsCallback);
                                  }

                                  function loadDirectionsCallback(piNPOiNTsList) {
                                      var l = piNPOiNTsList.length;
                                      var directions = new GDirections(NOTiFYPiNPOINTmap);
                                      NOTiFYPiNPOINTmap.clearOverlays();
                                      var directionsPanel;
                                      var wayPoints = new Array(1);
                                      var e = 0;

                                      if (l &gt; 1) {
                                          for (var i = 0; i &lt; l; i++) {
                                              wayPoints[e] = new GLatLng(piNPOiNTsList[i][0], piNPOiNTsList[i][1]);
                                              e++;
                                              if ((((e % 25) == 0) &amp;&amp; e != 0) || (e == l)) {
                                                  directions.loadFromWaypoints(wayPoints);
                                                  e = 0;
                                              }
                                          }
                                      } else if (l == 1) {
                                          var wayPoints = new Array(1);
                                          wayPoints[0] = new GLatLng(piNPOiNTsList[0][0], piNPOiNTsList[0][1]);
                                          var marker = new GMarker(wayPoints[0]);
                                          NOTiFYPiNPOINTmap.addOverlay(marker);
                                      }
                                  }
                                  </script>

                          In the Interface I have;

                          @WebRemote
                          String [][] getPiNPOiNTsListAsArray();

                          Works fine now!
                          • 10. Re: Seam Remoting - Getting values!
                            Janine Graul Newbie

                            Thank you very much. It works for me too.