Monday, February 21, 2011

how to iterate a arraylist of object

Dear all, i m using dao design pattern in which i m returning a arraylist object ,inside object i can fetch by typecasting object into class and acees the getters like object.getName(),i want to itearate using a jstl tags.how can i do that.

From stackoverflow
  • <c:forEach items="${yourArrayList}" var="item">
        <c:out value="${item.name}" />
    </c:forEach>
    

    The objects you put in your collection should conform to the JavaBeans specification (for ex. all of their properties should be accessible via getter methods).

    ${yourArrayList} is actually a request attribute that you have put from a servlet and then forwarded to the jsp.

  • Ok with Bozho.

    I will just say that if you redirect a servlet to jsp (which is better than calling dao from scriptlets...) don't forget to put your object that will be used in jstl in a pagecontext scope like request or session. Without that jstl lib would never find your object...

0 comments:

Post a Comment