Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

mandatory attributes for c:forEach

 
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
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?

Thanks,
Raj
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please post your code which you have tried and also the exception details?
 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)


I think this is vendor specific.
 
raj malhotra
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the JSTL specs I can read this

<c:forEach>
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.
 
raj malhotra
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aj Deschanel,

that makes sense.

Thanks,
Raj
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic