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

 
Sahul Yasin
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets say, "name" is a String property of a class "Person" and
has a value "Arnold".

Line 1: <jsp:useBean id="person" class="Person" scope="request"/>
Line 2: <%request.setAttribute("name","TomCruise");%>

What will be the values of the below expressions:
1.${person.name}
2.${person[name]}
3.${person["name"]}

Thanks is advance.
 
Hunny Lee
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sahul Yasin:
What will be the values of the below expressions:
1.${person.name}
2.${person[name]}
3.${person["name"]}

[/QB]


1 - Arnold
2 - Throws an Exception. Something like "Unable to find a value for 'TomCruise' in class Person". This is because "name" is evaluated first. So the EL would be something like ${person["TomCruise"]} afterwards. Since TomCruise does not exist as a property, this will throw an exception.
(Note: Even if you had getTomCruise() in your Person bean, this would still not work, since the "name" attribute has a capital T in "TomCruise". To make it work, set the attribute as "tomCruise" [lowercase t]. It will then print out whatever getTomCruise() returns)
3 - Arnold


I hope that helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic