admin管理员组文章数量:1398782
I know that this is a very noob and dumb question, but I need help. Tried several topics and none's working.
So I'm trying to pass a List created in Struts2(java) into javascript to draw a chart using highlight. I've read several articles and e up with this:
$(function drawList() {
var list = [
<c:forEach items="${listFromJava}" var="alistFromJava">
{itemName: "${alistFromJava.attribute}"},
</c:forEach>
];
However it never works, and always ends up with: Static attribute must be a String literal, its illegal to specify an expression.
If I try:
list = '<s:property value="listFromJava"/>
then it returns the reference only.
Any suggestion is appreciated. Thanks in advance.
I know that this is a very noob and dumb question, but I need help. Tried several topics and none's working.
So I'm trying to pass a List created in Struts2(java) into javascript to draw a chart using highlight. I've read several articles and e up with this:
$(function drawList() {
var list = [
<c:forEach items="${listFromJava}" var="alistFromJava">
{itemName: "${alistFromJava.attribute}"},
</c:forEach>
];
However it never works, and always ends up with: Static attribute must be a String literal, its illegal to specify an expression.
If I try:
list = '<s:property value="listFromJava"/>
then it returns the reference only.
Any suggestion is appreciated. Thanks in advance.
Share Improve this question edited Oct 2, 2013 at 9:46 Andrea Ligios 50.3k29 gold badges124 silver badges248 bronze badges asked Oct 1, 2013 at 3:34 user1509803user1509803 1961 silver badge9 bronze badges1 Answer
Reset to default 6To avoid confusion while googling:
<c:forEach
is JSTL
${listFromJava}
is EL
<s:property
is STRUTS2 UI TAG
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 ma, 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"
).
本文标签: javascriptStruts html tag inside ltscriptgtStack Overflow
版权声明:本文标题:javascript - Struts html tag inside <script> - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744610646a2615634.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论