Reputation: 624
I have the following code in javascript:
<script type="text/javascript"
src="#{facesContext.externalContext.requestContextPath}/js/sample-points.js"></script>
<script type="text/javascript">//<![CDATA[
var cloudmade = new CM.Tiles.CloudMade.Web({key: 'bbb'});
var map = new CM.Map('cm-example', cloudmade);
map.setCenter(new CM.LatLng(51.50874, 22.76367), 4);
var markers = [];
for (var i = 0; i < samplePoints.length; i++) {
markers.push(new CM.Marker(new CM.LatLng(samplePoints[i][0], samplePoints[i][1])));
}
var clusterer = new CM.MarkerClusterer(map, {clusterRadius: 70});
clusterer.addMarkers(markers);
//]]></script>
"samplePoints" is an array of coordinates which I can use to show markers on the map.
Map is showing here:
<div id="cm-example" style="width: 99.5%; height: 600px"></div>
How can I provide this array from jsf/richfaces without using file (e.g. I want to fetch those data from db, create array and send to this script)?
Thanks
Upvotes: 1
Views: 2806
Reputation: 1108632
Just let JSF print it as if it is JavaScript code.
Replace
var markers = [];
for (var i = 0; i < samplePoints.length; i++) {
markers.push(new CM.Marker(new CM.LatLng(samplePoints[i][0], samplePoints[i][1])));
}
by (assuming Facelets)
var markers = [];
<ui:repeat value="#{bean.samplePoints}" var="samplePoint">
markers.push(new CM.Marker(new CM.LatLng(#{samplePoint[0]}, #{samplePoint[1]})));
</ui:repeat>
where #{bean.samplePoints}
returns a List<BigDecimal[]>
or something.
Upvotes: 2