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

EL Implicit object paramValues

 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have request parameterd called name who has multiple values say "Imran" & "Vohra".

Now, when I am writing,
${paramValues.name[0]} -> its printing "Imran"
${paramValues.name} -> its printing String[] Object reference
${paramValues[name]} -> its not working.
${paramValues[name][0]} -> Its not working

I am confused in last two. Why its not working? Whats wrong?
Please help me.

Imran
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

${paramValues[name]} -> its not working.
${paramValues[name][0]} -> Its not working


It's not working because when using EL, everything you put within brackets is evaluated first if it's not within quotes.

So, in the last two examples you provided above, the container tries to find an attribute called as name in either page, request, session or application scopes and NOT a param as you would expect.
 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh.....I got it
Thanks
In [] operator if quotes are not there then it must be either implicit object or key(for Map) or index(for List and Array) or property (for bean).
I hope I am right this time.

Thanks once again
Imran
 
cheenu Dev
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you left what Edisandro Bessa said.
its an attribute.if you dont have quotes.
better verify pg number 375 in hfsj.
 
Cai DongShan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imran,

In [] operator if quotes are not there then it must be either implicit object or key(for Map) or index(for List and Array) or property (for bean).


Wrong.

1. If quotes are there, it can be a Map key or a bean property or an index (for List and Array)
2. If quotes are not there, it can be attribute or an index (for List and Array)
 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks....for correcting me.

Imran
 
krish bulusu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the aboue case ${paramvalues.name} should print "imran" right??
can anybody correct me if i am wrong!!
thanks,
regards
krishna!!
 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, ${paramValues.name[0]} will print "Imran".
Because ${paramValues.name} will return an array.

Thanks
Imran
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

No, ${paramValues.name[0]} will print "Imran".
Because ${paramValues.name} will return an array.


Incorrect !

Whenever you use ${paramValues.name} whithout specifying an index, ALWAYS will be returned the first element of the array.
 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this time I am not wrong.
If you write
${param.name}
then it will print first element, but if you write
${paramValues.name} then it will not print first element.

I have tested that with Tomcat 5.0



And my URL was



Its printing object reference.

Please confirm the same.

Thanks
Imran
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yeah, you're correct.

My explanation above is valid only when using the following statement :

${param.name}

In this case, if name is has more than one value, the statement above will return the first element.

But if you use ${paramValues.name} the toString() version will be called instead.

Very good discussion.
[ August 24, 2006: Message edited by: Edisandro Bessa ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic