This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Difference between [c:forEach] and [logic:iterate] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Difference between [c:forEach] and [logic:iterate]" Watch "Difference between [c:forEach] and [logic:iterate]" New topic
Author

Difference between [c:forEach] and [logic:iterate]

Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
I have seen some posts that discussed about <logic:iterate> tag. Seems to me that, this tag is going to loop through a list or collection and access it one by one. I have not used it before, but it seems provide similar functions as <c:forEach>.

Could anyone tell me the major difference between the <c:forEach> tag and <logic:iterate> tag?

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The JSTL c:forEach tag is standard and is often recommended over Struts' logic:iterate.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Note: - Many of the features in this taglib are also available in the JavaServer Pages Standard Tag Library (JSTL). The Struts team encourages the use of the standard tags over the Struts specific tags when possible.

The "struts-logic" tag library contains tags that are useful in managing conditional generation of output text, looping over object collections for repetitive generation of output text, and application flow management


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi Lasse,

If it is recommended to use JSTL core library, why I saw some many people try using Struts' <logic> tag, instead of <c> tag?

That's really interesting.

And that's why I wanna know, is that becos something that <logic> can do, but <c> cant, so, people try to use <logic>.

Nick
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Nicholas Cheung:
If it is recommended to use JSTL core library, why I saw some many people try using Struts' <logic> tag, instead of <c> tag?

Perhaps because the vast majority of application servers in production today don't have JSTL support, yet.
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
Hi Lasse,

Perhaps because the vast majority of application servers in production today don't have JSTL support, yet.


You can support JSTL as well as Struts tag-lib.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by surasak lee:
You can support JSTL as well as Struts tag-lib.

Yes, if you're using a recent-enough application server or if you download and "install" a JSTL implementation. What I meant was that JSTL taglibs are not available out-of-the-box on most application servers in production today (for example, Tomcat 4.1 represents a big share of what's out there and plain vanilla Tomcat 4.1 does not include the JSTL taglibs...).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Difference between [c:forEach] and [logic:iterate]
 
Similar Threads
struts el + html:text-el question
dynamic logic:iterate
Array dispaly
Data display in table usinf logic:iterate tag
nested:iterate tag