How to access a java list coming from the server in javascript inside my jsp -
plz consider scenario. have java class called person below:
person --------- integer id string name string address
now through spring controller pass list of persons jsp page(neighbors.jsp) shown below:
list<persons> persons = new arraylist<person>(); . . . return new modelandview("/neighbors").addobject("persons", persons);
now problem here. have google maps api in javascript format embedded in neighbors.jsp display location of person logged in. works fine. google maps offer comparison of addresses. want display markers of addresses of other persons within 5 miles range of user's address. each of marker link page going display particular person's information.
suppose access each address in following format, how call javascript function?
<c:foreach items="${persons }" var="person"> <!-- want pass each address ${person.address} javascript functions thats going compare addresses --> </c:foreach>
can me out here on how handle scenario?
two ways it:-
first way... can set value hidden field allows javascript access it:-
<c:foreach items="${persons}" var="person" varstatus="i"> <input id="address${i.count}" type="hidden" value="${person.address}"> </c:foreach>
in javascript:-
yourjavascriptfunction(document.getelementbyid("address1").value);
second way... use <script>
tag in <c:foreach>
tag:-
<c:foreach items="${persons}" var="person" varstatus="i"> <script> yourjavascriptfunction("${fn:replace(person.address, "\"", "\\\"")}"); ... </script> </c:foreach>
Comments
Post a Comment