java - jsp tag inside javascript -
i have objects of 2 classes returning servlet on jsp page.
public class port { private string portname; private boolean acceptability; //getters , setters ... }
this components class have ports objects
public class component { private int id; private string name,icon; private list<port> inputports; private list<port> outputports; //getters , setters ... }
this java script code
<script> makecomponent("menu", "image.png", "green", [makeport("input", true)], [makeport("output", false)]); </script>
and want put object value inside script tag
i tried not working
<script> <c:foreach items="${components}" var="component"> makecomponent("${component.name}", "image.png", "green", [<c:foreach items="$components.inputports" var="inputport"> makeport("$inputport.portname", ${inputport.acceptability}), </c:foreach>], [makeport("out", false)] ); </c:foreach> </script>
is logic correct? can use jstl tags in javascript block?
exception ',' after makeport function
i added: <c:if test="${!loop.last}">,</c:if>
code , works
<c:foreach items="${components}" var="component"> makecomponent("${component.name}","images/55x55.png","green", [ <c:foreach items ="${component.inputports}" var="port" varstatus="loop"> makeport("${port.portname}", ${port.acceptability}) <c:if test="${!loop.last}">,</c:if> </c:foreach> ], [ <c:foreach items ="${component.outputports}" var="port"> makeport("${port.portname}", ${port.acceptability}) <c:if test="${!loop.last}">,</c:if> </c:foreach> ]);
Comments
Post a Comment