• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock test Doubt on EL

 
rachna jain
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please refer q-7 on page 795

can some explain this.

I am not getting how it is evaluated.


one imp doubt is that if we use

${a.b}

a is bean or map then will this expression wont give value of b or it will give just b object

${cookie.JSESSIONID} wont it give value of jsessionid.

I am confused please clarify i have my exam day after tommorrow
 
Mateus Lucio
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rachna

${a.b} - this will return the b object

if ${a.b} is being printed then
if b is a primitive or a string then you get it's value otherwise you will get it's string representation, which is equivalent to b.toString()

samething with cookie.JSESSIONID or any other cookie

cookie implicit object is a map which means that cookie.JSESSIONID return a cookie object, if you want its value then use cookie.JSESSIONID.value
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is what the el 'dot' operator or brackets [] do for you:

  • If it's a property that follows the JavaBean Standard, it calls the getProperty() method so ${obj.value } ends up in a call to getValue() on obj


  • In case of arrays it accesses the index you define. be aware that with arrays you can only use the bracket syntax ... So an Array of Strings is accessed like this ${arr[0] }, the same applies for Lists, as those are fancy Arrays in a way


  • with Maps, EL accesses the key and returns it's value... so for a map entry with key=key and value=value --> ${map.key } returns value
    if the key is numeric, you are not allowed to use the dot operator


  • the tree can go deep down ...

    imagine you have an array and on index 0 there is a Map<String, SomeBeanObject>, that has a key=bean and SomeBeanObject has a property called beanValue which returns a String, then you would access it with

    ${ arr[0].bean.beanValue }

    what happens under the covers is this


    hope this helps



     
    rachna jain
    Ranch Hand
    Posts: 76
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    so as cookie is a map and jsesisonid (name of a cookie) is not numeric so it will return cokkie object not its value.


    Thanks a lot.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic