and you can also provide a method do your component/page java class, say
String getPointsJsArray()

and provide it as input-symbol to your script.

kiuma

On 1/29/07, Matt Brock <[EMAIL PROTECTED]> wrote:



Bastian Voigt wrote:
>
> I have a simply question: is it possible to pass an array to a
javascript
> included with @Script? How can it be done?
>
> I have an array of Point objects (which consist of a latitude and a
> longitude
> value) and I want to pass them to my script, so that the line of points
> can
> be displayed on a map.
>

Yes, this is fairly easy using the FOREACH declaration inside the SCRIPT
definition.  It works much like the FOREACH component.

So, for example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script PUBLIC "-//Apache Software Foundation//Tapestry Script
Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Script_3_0.dtd";>
<script>
  <input-symbol key="pointsArray" class="java.util.ArrayList"
required="yes"/>
  <body>
    var Points = {
      elements: [],
      pointsObj: function(latitude, longitude) {
        this.latitude = latitude;
        this.longitude = longitude;
      },
      add: function(id, latitude, longitude) {
        Points.elements[id] = new Points.pointsObj(latitude, longitude);
      },
      remove: function(id) {
        delete Points.elements[id];
      }
    };
  </body>
  <initialization>
    <foreach expression="pointsArray" key="keyPoint">
      Points.add(${keyPoint.id},${keyPoint.latitude},${keyPoint.longitude
});
    </foreach>
  </initialization>
</script>

The body is just creating a simple JavaScript object to hold your points
for
easy access, plus a couple of convenience methods.  The real meat is in
the
initialization part.
--
View this message in context:
http://www.nabble.com/Passing-Array-to-JavaScript---tf3122349.html#a8684293
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to