• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFS question 15 page # 423

 
Sandya Bhaskara
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the MyBean class params,objects and name are not explicitly initialized..so they will be initialized to null..and the corresponding get methods return null...so how come there wont be errors for options A B D and E?? the answer says C and F will give errors because list objects will not hav properties...and what is that property "a"???it is no where in the program...quite confused
 
Sandya Bhaskara
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


which will cause errors -assume that an attribute named mybean can be found and is of type MyBean?

A.${mybean.name}
B.${mybean["name"]
C.${mybean.objects.a}
D.${mybean["params"].a}
E.${mybean.params["a"]
F.${mybean["objects"].a}
 
Sandya Bhaskara
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is that something to do with polymorphism?the question mybean is an attribute for object of type mybean=>mybean is an attribute of the object a class that extends mybean ??in that case understood the question..but am i right??
 
Jeff Huxley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the same question. I'm looking at question #15 on page 423 and don't get what "a" is. Is this a typo? If it�s not I�m missing something and would appreciate a little guidance. Thanks
 
Henrik Krievs
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi' !

I've tried to code the example - and I don't get any errors at all....

But, I think, according to HF - if and attribut is missing/lacking - EL would ignore that. So I think, in the example, the 'a' - is supposed to be an map-key....

Rgds, Henrik
 
Gabriel Forro
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I try to explain it:
1. You have a bean 'MyBean', which has 3 properies: name, objects, params
2. You can access a bean and its properties through EL on a JSP page. So ${mybean.objects} returns a List object
4. You can access the items in List objects through EL as well, but You must use [] instead of . operator, so ${mybean.objects.a} is not correct
5. List interface has not got a getA() 'bean like' method, at the same time List is not a Map, so ${mybean.objects.a} is not valid EL expression.

Note:
If You try to acces a property, which is not defined for the bean, for example ${mybean.notAProperty}, You get a javax.servlet.jsp.el.ELException exception.
 
Henrik Krievs
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gabriel !

I don't get any exceptions [using Tomcat 5.xx.28] - even if I write
${myBeanThatDonotExist.attrib} ??

- Shouldn't it give some kind of error ?

Rgds, Henrik
 
Gabriel Forro
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Henrik,

Yes You don't get, as the bean does not exist.
If you try:
${myBeanThatExists.attribThatDoesNotExists}

You get a nice exception
Let's say we have ${X.Y} EL expression
If the first section of the EL (e.g. ${X. ) evaluates an object and that object is not a Map and it does not have a getY() function, than an exception is throwed.
[ October 11, 2004: Message edited by: Gabriel Forro ]
 
sam siu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, the bean is still legal even without setter methods? Or if the expression is not map, list or array, it will be treated as a bean automatically without checking whether it's a legal bean and getter method will be called. Anyone could me help me clarify this?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic