Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in EL

 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
10. public class MyBean {
11. private java.util.Map params;
12. private java.util.List objets;
13. private String name;
14. public java.util.Map getParams() { return params;}
15. public String getName() { return name; }
16. public java.util.List getObjects() { return objects; }
17. }


Which will cause errors(assume that an attribute name mybean can be found, and if of type MyBean)? (Choose all that apply)
A. ${mybean.name}
B. ${mybean["name"]}
C. ${mybean.objects.a}
D. ${mybean["params"].a
E. ${mybean.params["a"]}
F. ${mybean["objects"].a}

The answers are C and F.
Can you tell how they have arrived at this answer?
With regards,
Padma priya N.G.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're asking a lot about fundamental EL since yesterday. Please read your book, and refer to the specification to understand how the "." and "[]" work. Then ask what you do not understand.
Please understand that your questions are difficult to answer, because they deal with fundamental things which take time to explain. You don't seem to have read anything about EL before asking.
JSP.2.3.4 Operators "[]" and "." from the specification will answer most of your questions.
 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am unable to understand why option 'F' is chosen as the correct answer?
With regards,
Padma priya N.G.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that a.b is the same as a["b"] ? C and F are the same. So if you understand C, you'll understand F You can only access a list via an index (integer), and "a" is not an index. When accessing a list, the container will try to call a.get(b), so b must be an integer.

(by the way, line 12 has a typo)
 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks.
With regards,
Padma priya N.G.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic