struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Nenning <Christoph.Nenn...@lex-com.net>
Subject Re: Struts 2.3.28.1 - Populate Java Property from Controller inside JavaScript
Date Mon, 29 Aug 2016 07:15:30 GMT
> Hi all,
> 
> First of all, greetings, from Brazil.
> 
> I would like to populate this Java Script variable with name
> *flightPlanCoordinates
> *from a Action Controller.
> 
> var flightPlanCoordinates = [
> 
> 
> {lat: -23.533592, lng: -46.742744},
> 
> {lat: -23.533592, lng: -46.742744},
> 
> {lat: -23.533870, lng: -46.742804},
> 
> {lat: -23.533978, lng: -46.742890}
> ];
> 
> Whats the best approach to do? I how can I use tag libs from Struts to
> mount this *flightPlanCoordinates ?*
> 
> 
> Thanks in advance,
> 
> 
> Bisconcini


Hi,

it depends how your java classes look like.

If you have a class like this one:

public class Coordinates {
        private double lat;
        private double lng;
}


You could have a list in your acton:

public class SomeAction {
        private List<Coordinates> coordinates;

        ...

        public List<Coordinates> getCoordinates() {
                return coordinates;
        }

}


In a JSP you could access coordinates like this:

var flightPlanCoordinates = [
<s:iterator value="coordinates">
        {lat: <s:property value="lat" />, 
        lng: <s:property value="lng" />},
</s:iterator>
]


Be aware that this is just a very simple example. You should adjust it to 
your app.


Regards,
Christoph

This Email was scanned by Sophos Anti Virus

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message