0 Replies Latest reply on Apr 27, 2010 12:58 PM by peterlen

    Passing objects in EL Expressions to Javascript functions... possible?

    peterlen

      Hello,

       

      I have something like the following:

       

      <a:outputPanel id="map_coords">

         <script type="text/javascript">

            function addMarkers() {

              <ui:repeat value="#{searchGeoItems}" var="gi">

                addResultMarker("#{gi.uri}", #{gi.points['0'].latitude}, #{gi.points['0'].longitude}");

              </ui:repeat>

            }

         </script>

      </a:outputPanel>

       

      The goal is that for each of my searchGeoItems (say there are 20) I am calling a javascript function and passing in three items.  Each of these items ends up being a string that gets passed to the function.  All works fine in this manner.   In this example you can see that the 2nd and 3rd parameters are values from an object which is the first object in a List.  So in the backing bean there is a list of Point objects and each Point has a latitude and longitude.  In this example only the first Point object's latitude/longitude are being passed to the javascript function.

       

      What I want to do is somehow pass the entire list of Point objects to the javascript function so that I can get the latitude / longitude for each Point.  I tried to just do the following:

       

            addResultMarker("#{gi.uri}", #{gi.points});

       

      hoping that a JSON object would be created and passed, but this is not the case.  Is there a way to use EL Expressions so that an object is generated and useable rather than simply a eveluating things to strings?  I imagine that I could have another <ui:repeat> added to go though the #{gi.points} object but that isn't what I would need.  The only other option I can think of is chnage it so the the backing bean concatenates all of the lat/long values into a string and then have the javascript function parse the string.

       

      Does anyone know if you can obtain/pass objects (like a string array) in this manner instead of just primitive strings (similar to how you can do it with SEAM Remoting)?

       

      Thanks - Peter