问题
I am using facelet and draw function has jstl tag:
<ui:define name="content" >
<h:outputScript name="js/graphics/paths.js"/>
<h:outputScript name="js/graphics/draw.js"/>
Tag to be evaluated when function is called(is that possible)?
function showMap(){
var data = {
<c:forEach items="${list.KPI}" var="ctag" varStatus="loop">
'${ctag.USTER}': ${ctag.Value}
${!loop.last ? ',' : ''}
</c:forEach>
}
}
Error:
Is it possible to use jstl with facelets? Why am i getting this error? I am using there links:
1) is it possible for javascript to extract value from cforeach tag
2) populating-javascript-array-from-jsp-list
回答1:
Surely JSTL works in Facelets. There are only some technical implications which can only be understood by really understanding the Facelets lifecycle: JSTL in JSF2 Facelets... makes sense?
As to your concrete problem, you most likely forgot to declare the JSTL taglib in the XML namespace.
xmlns:c="http://java.sun.com/jsp/jstl/core"
Not doing so would cause the JSTL tags not being interpreted at all and end up in a syntax error in the generated HTML/JS code because JSTL tags are not recognizeable by the webbrowser as valid HTML/JS code. Rightclick page in webbrowser and do View Source. You should not see any unparsed/plain JSTL tags in there.
来源:https://stackoverflow.com/questions/11733867/reading-bean-list-using-jstl-and-assigning-to-javascript-variable-in-facelets