Which of the following lines of code, if inserted independently at Line 5, will cause the text within the c therwise tag to display? (Choose all that apply)
A. books.add(""); B. books.add(null); C. books.clear(); D. books.add("Head First"); E. books = null;
Thank you - very nice explanation. I am suprised that the last option with the null did not work. I found this on the sun site regarding the empty operator and the EL
The language offers the following operators (parentheses here are used only for grouping):
(empty) operator, which evaluates to true if the expression evaluates to null, or evaluates to a container object that contains no items.
ternary operator for simple if-then-else (?
Hema Nandhini
Ranch Hand
Joined: Aug 04, 2008
Posts: 31
posted
0
option E is correct. I tried it and it jumps to the otherwise condition. 'empty' works for empty lists and also if the object as such evaluates to null, as Micheal said.
SCJP 1.4 (86%)<br />SCWCD 1.5 (88%)
Milind Patil
Greenhorn
Joined: Oct 19, 2003
Posts: 26
posted
0
Hi,
I checked with JSP2.0 Specification (Page: 1-73 Point: JSP.2.3.7). This is what I got from it.
JSP.2.3.7 Empty Operator - empty A The empty operator is a prefix operator that can be used to determine if a value is null or empty. To evaluate empty A, � If A is null, return true, � Otherwise, if A is the empty string, then return true. � Otherwise, if A is an empty array, then return true. � Otherwise, if A is an empty Map, return true, � Otherwise, if A is an empty Collection, return true, � Otherwise return false.
I also ran the example provided. For answers C and E, I got output as "I have not selected any favorite books."
Thanks - I did not realize that containers can implement different behavior for the EL 'empty' operator. I thought they were allowed to implement any way they choose but be required to meet the spec.
I thought they were allowed to implement any way they choose but be required to meet the spec.
They do, but sometimes don't. Of course, they won't blunder such simple things like 'empty'. I didn't encounter much non-spec friendly behavior in SCWCD, but more in SCBCD. So trying something with a container is good, but does not guarantee 100% correctness.
Michael Ku
Ranch Hand
Joined: Apr 20, 2002
Posts: 510
posted
0
Understood. I just had noticed that some posts were giving incorrect answers/information and thought that it would be better to have these posters discover the error for themselves. I tried to give a gentle nudge in the right direction :-).
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.