Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About EL cookie Implicit object

 
Sanjay pts
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
all.
If we get value from param/initParam/header implicit object like this

param.empID
initParam.adminEmail
header.host

then for cookie why its like
cookie.userName.value
why its not cookie.userName ???

thanx
sanjay
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know... maybe it is because a cookie is physically stored as a name/value pair on the client computer, and the entire name/value is put into the cookie map.

It doesn't make much sense, but it wouldn't be the first time that something in EL didn't follow the common sense rule (After all, HFJ&S is dedicated to whoever decided that the EL implicit object for a context param should be named initParam...)

I wonder if ${cookie.userName.name} would return "userName"?
 
osman cinar eren
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the other Maps, the value is a String. But in the cookie Map, the values are Objects, not Strings. You take the value parameter of the Object.

Hope this helps.
 
Harshana Dias
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
osman cinar eren wrote:in the other Maps, the value is a String. But in the cookie Map, the values are Objects, not Strings. You take the value parameter of the Object.


Cookie is not a map. its a normal class which take both String as parameters.
eg:
Cookie cok=new Cookie(Sting username, String value);

and that is where it makes diferent because those param,initParam, header are Map objects having key/value where when we give the key it gives us the value.
eg: param.empID // empID is the key here of param Map and also its returns type Object right so cast is needed i guess..is it right?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65338
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This post is over 4 years old. Please read this.
 
Harshana Dias
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:This post is over 4 years old. Please read this.


yes but last answer is wrong know...some one may misunderstand the question because of it
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Harshana. As Osman said
in the other Maps, the value is a String. But in the cookie Map, the values are Objects, not Strings. You take the value parameter of the Object.
I think it is true.
EL 'cookie' is an implicit object(map object). Here Cookie object(java object) stores in map object like this,
If we say ${cookie} container will get EL implicit object(map object). We know map object stores as name/value pairs. Here if we say ${cookie.user}(here is 'user' is key of map object), we will get Cookie object(cookie). If we want value out of it, we have to say ${cookie.user.value}.
 
Harshana Dias
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Chinmaya thank you for the reply. i was stupid i thought of Cookie object it self not the EL cookie.

by the way we know in a map have a method called,

Object get (Object key) right? // returns type Object

So if we say param.empID is it like invoking this method passing the key (empID) as argument for this method? If so return type is Object know so why dont we need a cast like..(String)param.empID ?
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hashana. We know form parameters name/value pairs are of type String. Here we don't need to cast, EL will take care of it. Moreover if we see J2SE6.0 HashMap api , the type of value we set in 'put(K key, V value)' and the container will return that type 'V get(Object key)'.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic