• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

right to the dot operator should be a bean property?

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
chapter 8, p423, q 15.

public class MyBean {
private java.util.Map params;
private java.util.List objects;
private String name;
public java.util.Map getParams() {return params;}
public String getName() {return name;}
public java.util.List getObjects() {return objects;}
}
Which will cause errors( assume that an attribute named mybean can be found, and is 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}

MyBean doesn't have a property "objects" or "name" or "params" coz no valid setter/getter methods for those properties.

So shouldn't all of them throw errors??? What is it that I am missing? Can someone plz explain?


regards,
Brian

[ July 10, 2005: Message edited by: Brian Percival ]
[ July 10, 2005: Message edited by: Brian Percival ]
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Brian ,

You are right in the sense that if we call a setter method then it would have definitily thrown an error .

But here the expressions result in calling only the gettter methods and hence
it works.

Whenever we output any expresion value then only the getter methods are called

If we had tried <jsp:setProperty> then it wouldnt have worked

Catch You Later
Shiva
 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't get it.. P 368 states under "using the . operator" that

"the thing to the right of the dot is either a map value or a bean PROPERTY if the first variable is an attribute that's a javabean.

But if something is a bean PROPERTY, doesn't that mean by definition of a property that it should have corresponding getx,setx methods? So then how come the "objects" etc in the MyBean class are considered properties of the bean???

regards,
Brian
 
shiva viswanathan
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Brian ,

You are confusing Bean Law and JSP Law

By bean law it is required for the bean to have getter and setter methods
And JSP law advocates that beans strictly follow this rule
so that we dont get an error when we do setProperty for eg

But there is no check in JSP itself to actually validate that the
bean being displayed follows the rules .You will get the error at run time

Hence in this case it has getter methods and we are accessing only the
getter methods when we do something like
beanname.property which will internally call
beanname 's getProperty method

In fact you can try this on any variable (even if it is not a java bean )but if it doesnt have the
getter method then nothing will be displayed

There is no check in JSP specs itself to ensure at complie time that
name on the left is a bean or map

Hope you get it

Thanks
Shiva
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic