• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot understand EL with Maps

 
balu balaji
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<% java.util.Map map=new java.util.HashMap();
request.setAttribute("map",map);
map.put("a","true");
map.put("b","false");
map.put("c","42");
%>
which three EL expressions are valid and evaluate to true?(choose three)
A.${not map.c}
B.${map.d or map.a}
C.${map.a and map.b or map.a}
D.${map.d or map.a}
E.${map.false or map.true}javascript: x()
i think A option return true is it correct are not


[ December 23, 2008: Message edited by: Christophe Verre ]
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15627
46
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

The forum you posted this in is for announcing that you passed a Sun certification exam. I will move this question to a more appropriate forum. Follow the link at the top of the page to continue.

Also, please use a meaningful subject line for your posts.
[ December 23, 2008: Message edited by: Jesper Young ]
 
balu balaji
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${not map.c} returns true
 
Kathiresan Chinna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Are the options B and D same ?

Kathir
 
Kathiresan Chinna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option A, B, C are true
 
Ulrich Borchers
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, greetings to everybody since this is my first post around here.

Could somebody please explain why this evaluates to true:
balu balaji wrote:${not map.c} returns true


imo not "42" should evaluate to "false". Why "true" then?

Cheers.
 
Kathiresan Chinna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Some body,

{ not "45" } returns true.

Kathir

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Some Body Else",
Welcome to the ranch. You may not be aware of the ranch Naming Policy. Please read it carefully and change your name accordingly (obviously fake names are not allowed). Thank you.
 
Ulrich Borchers
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:"Some Body Else",
Welcome to the ranch. You may not be aware of the ranch Naming Policy. Please read it carefully and change your name accordingly (obviously fake names are not allowed). Thank you.


Ok Christophe, I changed it.
 
Ulrich Borchers
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kathiresan Chinna wrote:Hi Some body,

{ not "45" } returns true.

Kathir



Thanks, Kathir. But can you tell me why it returns true or point me to some reading which shows how strings are evaluated as booleans?

My thinking was like this: ${ "45" } should be true, so ${ not "45" } must be false. But it is true. So I am a little confused by this.
 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As explained in the HFSJ,

In logical expressions EL treats unknown variable as false


So for ex:

If you had an attribute 'foo' with value 'true'

${not foo}

would return false.

But if there was no such attribute,

${not foo}

would return a true (as the 'unknown' -> foo variable evaluates to false)
-----

${not "45"}
is almost like the above one. So I guess it is seen as not(somethingNotKnown), thus returning a not(false) --> true.
 
Ulrich Borchers
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${not "45"}
is almost like the above one. So I guess it is seen as not(somethingNotKnown), thus returning a not(false) --> true.

Sounds reasonable, thanks.

Vishwanath Murthi wrote:As explained in the HFSJ,

Which page is it? Sometimes I wish, you could just hit <ctrl>+<f> in real books
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic