0

I have a requirement where I have to itearate over a map element kept in PageContext, inside jstl fore each . And I am also using an iterator inside the option tag. So I need to make sure the fore each loop iterate 1 less then the actual map size of map al, so that my iterator i is not iterated completely.

    select name="interval" id="interval" onchange="comeback()" >

    <% 
    String s="";
    s=(String)portletSession.getAttribute("int1"); 
    %>


     <option value="int">Time Interval</option>
     <c:forEach var="line" begin="0" end="<%= al.size()-1 %>" items="${al}">
     <option <%=((String)((Iterator)portletSession.getAttribute("i")).next()).equals(s)?"selected":" "%>  > <c:out value="${line.value}"/></option> 

    </c:forEach>

    <option value="others" <%=((String)((Iterator)portletSession.getAttribute("i")).next()).equals(s)?"selected":" "%> >> 60 Days </option>
    </select>

I tried using begin end but did not work out. Please help me out.

Regards

Afsun Khammadli
  • 2,048
  • 4
  • 18
  • 28
jayendra bhatt
  • 1,337
  • 2
  • 19
  • 41
  • You can quite easily iterate the Map keys and the Values for each key using standard JSTL. For example: http://stackoverflow.com/questions/29029272/jstl-hashmap-and-dynamic-key/29039563#29039563 – Alan Hay May 06 '15 at 15:11

1 Answers1

1
end="<%= al.size()-2 %>"

the last element you want should be al.size()-2, according to array's index

Leo Lee
  • 468
  • 5
  • 16