Forums Register Login

java 1.5 list iteration using jstl tag

+Pie Number of slices to send: Send
Hi,

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.



Thanks

krish
+Pie Number of slices to send: Send
<c:forEach> will iterate over anything that implements List.
[ October 23, 2007: Message edited by: Bear Bibeault ]
+Pie Number of slices to send: Send
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

Thanks
krish
+Pie Number of slices to send: Send
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:

+Pie Number of slices to send: Send
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.

Thanks
Krish
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
If you are unfamiliar with using the EL, the EL chapter of the JSP spec is a must-read.
+Pie Number of slices to send: Send
In this case, the JSTL spec is a must-read too. You'll find both here:
  • JSP 2.0
  • JSTL 1.1
  • We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 4602 times.
    Similar Threads
    Need help regarding s:select tag list
    retaining selected values.....list box
    How to reterive table row value (JSP )from the action class
    struts Action for asynchronous HTTP processing
    scriptlet processing query in JSP
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 28, 2024 03:00:16.