• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java 1.5 list iteration using jstl tag

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<c:forEach> will iterate over anything that implements List.
[ October 23, 2007: Message edited by: Bear Bibeault ]
 
krish chaitu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are unfamiliar with using the EL, the EL chapter of the JSP spec is a must-read.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this case, the JSTL spec is a must-read too. You'll find both here:
  • JSP 2.0
  • JSTL 1.1
  •  
    She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic