Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in the el map and bean access

 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When i say:

if the foo is found in the requestScope it will return the value if not requestScope is actually a map when the foo key is not found it will return null and prints nothing. But when i say something like this. this will give me a compile time error because in this case pageContext is a bean and not a map so when we say ${pageContext.foo} foo attribute is not present the PageContext class so it will throw up a compile time error.

So conclusion is.

When we have a map we wont get any error if the key is present it will return the value else it will return null and el prints nothing on the screen.
When we have a class We should call only those methods and attributes which are already defined in the class else we will get a compile time error is that correct?

Please correct me if i am wrong

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is that correct?

I think it is With a map, the Map#get(Object) method is called. Here, requestScope.get("foo"). If the key does not exist, null is returned. With a class, the getter will be called. For example, PageContext#getFoo(). This method does not exist, which results in an error.
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok Thanks,

In map we have getObject() which will be called for any key we pass in but for bean key specific get and set methods should be present if not compile time error is thrown.

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In map we have getObject()

get(Object)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic