how to get the element of a list inside jsp using JSTL?

I have such this code inside my Spring MVC java controller class:

@RequestMapping(value = "jobs", method = { RequestMethod.GET })
public String jobList(@PathVariable("username") String username, Model model) {
    JobInfo[] jobInfo;
    JobStatistics js;
    LinkedList<JobStatistics> jobStats = new LinkedList<JobStatistics>();
    try {
        jobInfo = uiClient.getJobs(username);
           for (int i = 0; i < jobInfo.length; i++) {
             js = uiClient.getJobStatistics(jobInfo[i].getJobId());
             jobStats.add(js);
           }
        model.addAttribute("jobs", jobInfo);
        model.addAttribute("jobStats", jobStats);
    }

which uiClient will get some data from database using RMI ... now I want to show the jobs & related statistic inside my JSP file using JSTL :

<c:set var="stats" value="${jobStats}" />
        <c:forEach var="jobs" items="${jobs}">
           <c:set var="jobID" value="${jobs.JobId}"/>
          <table>
            <tr class="tr1">
                <td>${jobs.Topic}</td>
                <td>${stats.get(i).No}</td>
            </tr>
          </table>
        </c:forEach>

How do I get the LinkedList elements of Model inside my JSP using JSTL? There might be no no counter i been put in scope for me.

Answers


In my opinion, the right answer is a combination of both of the answers you got:

use varStatus attribute of c:foreach tag

but:

"get" is not a jstl function.

<c:forEach var="jobs" items="${jobs}" varStatus="i">
   <c:set var="jobID" value="${jobs.jobId}"/>
  <table>
    <tr class="tr1">
        <td>${jobs.topic}</td>
        <td>${stats[i.index].no}</td>
    </tr>
  </table>
</c:forEach>

EDIT: this is the code finally used by the author of the question:

<c:set var="stats" value="${jobStats}" />
<c:forEach items="${jobs}" varStatus="i">
   <c:set var="jobID" value="${jobs[i.index].jobId}"/>
  <table>
    <tr class="tr1">
        <td>${jobs[i.index].topic}</td>
        <td>${stats[i.index].no}</td>
        <td>${jobID}</td>
    </tr>
  </table>
</c:forEach>

get is not a jstl function.

<td>${stats[i.index].No}</td>

use varStatus attribute of c:foreach tag

<c:forEach var="jobs" items="${jobs}" varStatus="i">
   <c:set var="jobID" value="${jobs.JobId}"/>
  <table>
    <tr class="tr1">
        <td>${jobs.Topic}</td>
        <td>${stats.get(i.index).No}</td>
    </tr>
  </table>
</c:forEach>

Need Your Help

jQuery $(window).resize(); equivalent event listener, that only fires on a specified axis change?

javascript events javascript-events jquery

I am looking for an event listener, what works like jQuery's .resize(), but only fires when the resized object (talking about the window) is resized in x axis, or both, but not in only y axis. - So

Developing for iOS on multiple computers, testing on a single device, advice?

iphone ios xcode certificate provisioning

I was looking for some advice on provisioning profiles / certificates etc... I use an iMac at work to develop on, and I also sometimes find myself checking out my code from git onto my MacBook Pro at