Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

question on EL

 
Heilien Tsui
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having problem on this question. partly because, i do not understand the question.

What is the question trying to describe ?


question.jpg
[Thumbnail for question.jpg]
question
 
Ankit Garg
Sheriff
Posts: 9597
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the question is fairly simple (wow I am weak at EL and still I got it ). The question is saying that there is instance of a class named Appliance in the application scope with the name - appl. Now that class has a map of properties. Now the question is not clear on the point that the name of the map is properties. So the Appliance class would look like this



So now when we write the EL

${appl.properties.name}

here appl refers to the instance of Appliance class, properties will get the properties map, in the map the question says that there is a key named "name" which has the value Cobia which is what we want to display.

In the second example, we use a request scoped attribute prop to get the name property. You must know that there are two ways of accessing a property of a map. So if we want, we could have written the above EL as

${appl.properties['name']}


Now here we have used a string name to refer to the key in the properties map. But if you remove the quotes, then the value in the square brackets will get evaluated. And we know that there is a request attribute named prop containing the value name. So we write this EL

${appl.properties[prop]}

So this EL will be first evaluated to

${appl.properties['name'}

and then the final value will get displayed...

[Edit: spelling correction]
 
Heilien Tsui
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit, a very detail explanation
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!