I have a Liferay portlet where I pass a String array from action phase to render phase in my .jsp file. I am able to access the array and iterate through it like this:
<c:forEach var="item" items="${arrayItems}">
<p>${item}</p>
</c:forEach>
This is just to check that passing the data works fine... However, I would like to pass this whole array to my javascript function (that handles rendering the data to canvas). Any idea how to do this?
So far, I have tried the following:
<%
String[] items;
items = new String[((String[])request.getAttribute("arrayItems")).length];
items = ((String[])request.getAttribute("arrayItems"));
%>
<script>
displayItems(<% arrayItems %>);
</script>
and also
<script>
displayItems(${arrayItems});
</script>
I know that this is probably very basic question, but there are not many tutorials about passing data in portlets on web (and when I found any, the approach worked only for single Strings, not arrays). Thanks for any tips!
PS: I checked that my javascript function works correctly:
<script>
displayMessages(["One", "Two", "Three"]);
</script>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…