java - How do I send data from Struts action to javascript? -
i'm trying create webb application using struts 2 , javascript , i'm having trouble passing data action javascript.
list i'm trying send/access:
list<markerclass> markers; markerclass defined acoprding belove:
final class markerclass { public integer objectid; public string street; public string streetnumber; public string zip; public string city; public integer statusid; public float lattitude; public float longitude; } the action includes getter markers:
public list<markerclass> getmarkers() { return markers; } in jsp-file have tried doing this:
<%@ page language="java" contenttype="text/html; charset=iso-8859-1" pageencoding="iso-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!doctype html> <html> <head> <script type="text/javascript"> function initialize() { var titel = ""; for(var i, "${markers}") { titel = titel+ "${markers[i].street}"; } } the browser substitutes "${markers}" "[se.fubar.test.markerclass@37a4, se.fubar.test.markerclass@9ad97c]"
i'm guessing there better , smarter way since i'm bit new struts , trying code while under influence of migrane answer elludes me.
you cannot use struts variable in javascript function , expect work. remember ${...} stuff gets processed before html page sent browser. time javascript rendered @ browser, left textual representations. need (check syntax, haven't used stuff while):
function initialize() { var title = ""; <c:foreach var="marker" list="${markers}"> title = title + "${marker.street}"; </c:foreach> } something along lines anyway... javascript seen browser like
function initialize() { var title = ""; title = title + "street1"; title = title + "street2"; title = title + "street3"; title = title + "street4"; } i hope makes sense , related asking. way, there better ways of accomplishing functionality building dynamic js etc. there built in struts 2 components can use?
Comments
Post a Comment