Hi, I am confused on question#2 on page 485 of HFSJ book. The question is:
Assumming the standard JSTL prefix conventions are used, which JSTL tags would you use to iterate over a collection of objects? (Choose all that apply.) A. <x:forEach> B. <c:iterate> C. <c:forEach> D. <c:forTokens> E. <logic:iterate> F. <logic:forEach>
The answer was only (c). My question is if they didn't say "Assumming the standard JSTL prefix conventions are used, ...", the answer would be (F), (C), and (A) right? If not, what would they be and why?
Hmm... If they hadn't said "standard naming conventions", then either the answer would be A, C and F as you say, or the pedantic answer would be "a translation time error would occur since no namespaces are bound to tag libraries in the page [and there is no evidence of any in the deployment descriptor either]". Thankfully, the question is well-written to avoid the problem!
Anyone please correct me if I'm wrong, but the exam never uses any prefixes other than "c" for JSTL Core, and "jsp" for JSP standard actions (actually, "jsp" is an intersting case - in a JSP page, you must use the "jsp" prefix for a standard action, while in a JSP document you can reassign the JSP namespace to any prefix you wish, not necessarily "jsp"!)
So, if you're asking for a general interest non-exam answer, then potentially any of A, C and F could be right, and this depends on how you declare the namespace/prefix mappings in the JSP/deployment descriptor (clearly B and E don't exist in the JSTL, and D only works on strings, not collections of objects, so these are all wrong regardless).
Hope that answers it for you! Charles. [ March 14, 2006: Message edited by: Charles Lyons ]
Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / AmazonAmazon UK )
The specification talks about prefixes used in the specification(c, x, fmt, sql, fn), but not perticularly about conventional prefixes. We could argue about who decided those "standard naming conventions"
There won't be such confusing questions at the exam.
I think it's become an adopted (de facto) standard convention. The prefixes used in the specification have been propagated into almost all the literature and code around - after all, is there anyone here who honestly doesn't use 'c' as the prefix for JSTL core tags in their applications? How about 'jsp' - does anyone use anything different in their JSP documents? Going off topic, 'xsl' is widely understood as the prefix for XSLT stylesheet elements, as that's what's used in the spec., but that doesn't have to be the case in every document!
Consistency is the key to making code easy to read and debugging straight-forward (hence the official Java coding conventions), so this is why it is widely understood that 'c' is for JSTL core, although potentially it could of course be used for anything.
We could indeed argue (successfully) that no-one decided the convention, because it has simply become widely adopted for uniformity, without any one particular origin.
Anyway, the exam will be clear in its intentions and will not contain such an open question, so that should resolve the issue (at least in this forum!)
Joined: Feb 23, 2006
Thank you so much for your replies and confirmations Charles and Satou!