I have an array list stored inside a javascript
code block. I am looking to extract this array list and iterate through it using the html
tag <c:forEach>
. How can I achieve this? Currently, I am able to display the array list using <h:outputText>
, but now I want to loop through each element in the list.
The structure of my array list in javascript
looks like this:
<script>
topCategory = new Array();
topCategory.push("one");
topCategory.push("two");
topCategory.push("threee");
topCategory.push("four");
</script>
I aim to iterate over the topCategory
array within an html
tag <c:forEach>
For example:
<script>
topCategory = new Array();
topCategory.push("one");
topCategory.push("two");
topCategory.push("threee");
topCategory.push("four");
After that, I will be looping through this list within a
<table width="100%">
<tr>
<td rowspan="2" width="20%">
<c:forEach items="#{topCategory}" var="cat">
<p:commandButton value="#{cat}"/>
</c:forEach>
</td>
</tr>