2

is there any way to perform a ui:repeat inside a javascript? this is what i'm trying to do.

var point;
<ui:repeat value="#{testController.allItems}" var="item">
  point = new google.maps.LatLng(item.latitude,item.longitude);
  createMarker(point, item.name, item.desc);   
</ui:repeat>

testController.allItems returns a list of entities with latitude and longitude and other values, i'm trying to do a store locator using google maps. createMarker adds marker to the map.

or is there a better way to do this?

Rong Nguyen
  • 4,143
  • 5
  • 27
  • 53
galao
  • 1,281
  • 8
  • 26
  • 50
  • Consider adding a simple REST service and just fetch the data and parse it in js. The approach that you're implementing is extremely disgusting. – Denys S. Jun 04 '14 at 16:28

2 Answers2

1

You can try(another option: c:forEach):

        <script type="text/javascript">
                var point;
                <ui:repeat value="#{s9.list}" var="item">
                   point = new google.maps.LatLng(#{item.latitude},#{item.longitude});
                   createMarker(point, #{item.name}, #{item.desc});
                </ui:repeat>
        </script>

If your function require String parameter, you should use '', for ex:

    google.maps.LatLng('#{item.latitude}','#{item.longitude}');
    createMarker(point, '#{item.name}', '#{item.desc}');
Rong Nguyen
  • 4,143
  • 5
  • 27
  • 53
  • 2
    If you're generating _javascript_ code with _java_ code, it is better to move it to a JSF composite component. It is a more reusable practice. You can look [Oracle tutorial](http://docs.oracle.com/javaee/6/tutorial/doc/giqzr.html) and this [BalusC](http://stackoverflow.com/questions/6359042/execute-javascript-from-a-composite-component) example. Regards, – Rodmar Conde May 07 '13 at 12:49
1

I had this issue (c:forEach would not work either). Using the <h:outputScript> tag instead of the <script> tag resolved the problem. With the <h:outputScript> tag I could use ui:repeat

Lavandysh
  • 531
  • 1
  • 7
  • 15