NeedsHelp
NeedsHelp

Reputation: 437

JSP/JSTL - How to loop through a list within a list?

I'm just starting to learn JSTL so I may be missing something obvious but how do you loop through a list that get through the ArrayList .get() method. I need to iterate through using a counter maybe i.e. .get(i).

JSP Code:

<c:forEach items="${processVariablesList}" var="customerHistoryVariables">
    <c:forEach items="${processVariablesList.get(0)}" var="variable">
        <li><strong>${variable.getName()}: </strong>${variable.getValue()}</li>
    </c:forEach>
</c:forEach>

Servlet Code:

ArrayList<List<HistoricVariableInstance>> processVariablesList = new ArrayList<List<HistoricVariableInstance>>();

            for(int i = 0;i<processList.size();i++){

                String processId = processList.get(i).getId();

                List<HistoricVariableInstance> variableList = historyService.createHistoricVariableInstanceQuery()
                        .processInstanceId(processId).list();

                processVariablesList.add(variableList);

            }

Upvotes: 4

Views: 2787

Answers (1)

Vlad
Vlad

Reputation: 346

Ty this:

<c:forEach items="${processVariablesList}" var="customerHistoryVariables">
    <c:forEach items="${customerHistoryVariables}" var="variable">
         <li><strong>${variable.getName()}: </strong>${variable.getValue()}</li>
    </c:forEach>
</c:forEach>

Upvotes: 4

Related Questions