• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL dot operator

 
Kanishka Ajwani
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q. 26 from Whizlabs practice exam III says that "." (dot operator) in EL cannot be used to access maps, lists and arrays.

What I learnt from HFJS is that "the dot operator in EL lets you access values by using a Map key or a bean property. For example, ${foo.bar} gives you the value of bar, where bar is the name of Map key into the Map foo, or bar is the property of bean foo".

Whizlabs questions are shaking my concepts, and I am getting confused by their questions over and over again...
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
El dot operator can be used with only JavaBeans and Maps. And,

If you have ${first.second}, then :
If first is a Map:
> If !first.containsKey(second) then return null.
> Otherwise, return first.get(second)

If first is a JavaBeans object:
> If second is a readable property of first, as per the JavaBeans specification:
> > If getter throws an exception: error
> > Otherwise: return result of getter call
> Otherwise: error.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A great resource is the official specification (servlets, JSP, JSTL). The JSP spec says:
expr-a.identifier-b is equivalent to expr-a["identifier-b"];

It also explains how expr-a and identifier-b are treated for Map, List, arrays and others. As you said, the "." can be used to access maps.

Maybe it's time to consider using Enthuware's mock exams instead. It should also be wise to report all the errors you've found to Whizlabs.
 
Kanishka Ajwani
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Abhimaran and Christophe. I had the same concept in my mind that the dot operator can be used only for Maps and bean properties. For lists, arrays or any other identifier which does not follow java naming conventions, we must use the [] operator.

Just got confused with the whizlabs questions.

Christophe, where can I report the flaws in whizlabs? I have my exam next week, so I don't think it makes sense to purchase Enthuware at the last minute. But I would surely recommend Enthuware to people taking this exam in the future.

Thanks.!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe, where can I report the flaws in whizlabs?

I have no idea Check their homepage, there must be some kind of email, or forums where you can report them. But as your exam is next week, you'd better concentrate on your preparation for the moment, and leave these for later.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are so many problems with Whizlabs exams, I used both for SCJP and SCWCD, but, hate it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic