To avoid confusion while googling:
listFromJava
(or %{listFromJava}
") is OGNL
The Struts2 Tag that replaces JSTL's forEach
is <s:iterator>
.
Your function may be rewritten in pure Struts2 like this:
$(function drawList() {
var list = [
<s:iterator value="listFromJava" >
{itemName: '<s:property escapeJavascript="true" value="attribute"/>'},
</s:iterator>
];
});
To prevent the last element to have an undesidered comma, use <s:if>
$(function drawList() {
var list = [
<s:iterator value="listFromJava" status="stat">
<s:if test="#stat.index>0">,</s:if>
{itemName: '<s:property escapeJavascript="true" value="attribute"/>'}
</s:iterator>
];
});
EDIT: added the escaping needed to prevent javascript injection issues (escapeJavascript="true"
).