• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL Query

 
Aditi Kamra
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i came across below two questions

1.What is the output of this page? (1 correct answer)
<html>
<body>
Result is ${"a" < "b"}
</body>
</html>
a.“Result is true”
b.“Result is false”

2.What is the output of this page? (1 correct answer)
<html>
<body>
Result is ${a < b}
</body>
</html>
1.“Result is true”
2.“Result is false”

Can anyone please explain the difference/answers to both of them

the answers are 1.(a) 2. (b)

Thanks ..
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Aditi,

1.What is the output of this page? (1 correct answer)
<html>
<body>
Result is ${"a" < "b"}
</body>
</html>
a.“Result is true”
b.“Result is false”

I think it gives output as "true" because it may compares the ascii values of characher a and b, as they are declared in double quote or single quote, but I am not sure.



2.What is the output of this page? (1 correct answer)
<html>
<body>
Result is ${a < b}
</body>
</html>
1.“Result is true”
2.“Result is false”


here it gives output "false" may be because here both a and b are null. ckeck it above for " Result is ${a==b)" it may give "true" because here both are null.

But i am not sure about both answers.
 
Chinmaya Chowdary
Ranch Hand
Posts: 432
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aditi.
In EL compares lexicographically, here 'true' is correct.

In while evaluating, EL chooses is there any attribute(a) associates with any scopes(like page, request, session, application) if found returns it, if not EL treats it as 'false' (since this is logical expression). After that it chooses attribute (b), since it is not available, it returns 'false'. Then evalates, "false < false" it returns 'false'.

For more information see coercions rules.
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditi please Quote Your Sources when you post a question...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic