iam using struts & jstl as my framework to develop web pages, i have a action class that will call one DAO & that DAO returns a List<DTO>,in my action class i have like
List<DTO> list=dao.getList(); so here iam getting the generic list as return,so i have to display this list in a jsp page while looping through the list
can any one please help me how i can iterate it in jsp page using jstl tag. i know that we have c:forEach,c:Iterator,but not sure how to iterate java 1.5 list.
Hi, Thanks for your reply,but still iam confused of using the c:forEach tage, as i have a List<DTO> list=dao.getList(); so as per jstl c:forEach syntax
<c:forEach var="x" items="..." > ... </c:forEach> what value do i need to give for var,items,how will i get the list in this tag, its very confusing,
so please can anyone let me know in detail how to implement this tag for my requirement
Before forwarding to the JSP, your action class must create a scoped variable using the list. Something perhaps like:
Then in the JSP you can use:
krish chaitu
Ranch Hand
Joined: Oct 09, 2007
Posts: 32
posted
0
Hi, thank you very much for your reply. my list is generally a java1.5 list,like List<DTO> & from this list i need to get the DTO objects ,so will <c:forEach will only get the values from the DTO .in general we will have fields & corresponding setter & getters.
in normal we will do like for(DTO dto:List list) & it will get the dto objects,
So can anyone let me know,how will c:forEach approach my requirement.
Within the body of the forEach, the scoped variable item will be each element of the List in turn. That means, since your list is a List<DTO>, that each item will be a DTO instance.
Michael Ku
Ranch Hand
Joined: Apr 20, 2002
Posts: 510
posted
0
You should look on the web for an example of the <c:forEach ...> tag. Find one that uses the EL and dot notation to access object properties.