File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes mandatory attributes for c:forEach Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "mandatory attributes for c:forEach" Watch "mandatory attributes for c:forEach" New topic

mandatory attributes for c:forEach

raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 288
I was going through the online Jstl tld documentation. I found that required value is false for all the attributes in c:forEach.But if dont mention any attribute in c:forEach i am getting runtime exception.Is something wrong in documentation?

Shruthi Sam
Ranch Hand

Joined: Jul 09, 2008
Posts: 73
Can you please post your code which you have tried and also the exception details?
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi, Raj.

In 'c.tld' of standard.jar file also, all <required> element's of <attribute> are marked as false. This is from c.tld file,
I tested in Tomcat5.5.9 without specifying any attributes(c:forEach />) and I got exception
org.apache.jasper.JasperException: /testForEach.jsp(14,0) <h3>Validation error messages from TagExtraInfo for c:forEach</h3>

isValid() == false


I think this is vendor specific.
raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 288
Yes i also got the same exception.

i used to test, if it executes without showing any exception.Since its mentioned in the documentation that no attribute is required we should not get any excpetion.
Aj Deschanel
Ranch Hand

Joined: Oct 20, 2009
Posts: 40
From the JSTL specs I can read this

Repeats its nested body content over a collection of objects, or repeats it a fixed
number of times.

... what I understand is:
to iterate with c:forEach you need to provide either <items> or <begin> && <end> otherwise you can not iterate, that's why <items> && <begin> && <end> are not mandatory because you are allowed to skip one (items) or the other (begin && end), depending on what you are iterating over.

If you skip <items> you have to provide <start> && <end>.
If you have <items> you can skip <end> or both <start> && <end>

For the other attributes I guess it's easier to understand why they are not mandatory.

SCJP 1.6, SCWCD 1.5
raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 288
Hi Aj Deschanel,

that makes sense.

I agree. Here's the link:
subject: mandatory attributes for c:forEach
It's not a secret anymore!