i have objects of two classes which returning from servlet on jsp page.
public class Port {
private String portName;
private boolean acceptability;
//getters and setters ... }
this is my Components class which have Ports objects
public class Component {
private int id;
private String name,icon;
private List<Port> inputPorts;
private List<Port> outputPorts;
//getters and setters ...
}
this is my java script code
<script> makeComponent("Menu", "image.png", "green", [makePort("input", true)], [makePort("output", false)]); </script>
and i want to put object value inside script tag
i tried this but it is 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 this logic correct? can i use jstl tags in javascript block?
exception was ',' after makePort function
i added: <c:if test="${!loop.last}">,</c:if>
this code and it 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>
]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.