• 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

Polymorphism of the jsp:useBean

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose class foo.Employee is the sub-class of foo.Person, the following code set the properties of foo.Person or foo.Employee?? I think the answer is foo.Person, because it is the reference type...Right?

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sets the properties of both as its property="*"
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It sets the properties of both as its property="*"


No, * doesn't mean that it will set the properties of both person and employee. * means that it will get the parameters from request with the same name as properties in the bean and it will set them automatically by getting request parameters.

Secondly, the answer of your question is that it will set the properties of Person type because it is the reference type and if you have some properties defined inside Employee then those will not be visible to its parent.
 
Jon Lee
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am with Ali, I will try to test it using real code...
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Gohar:
Secondly, the answer of your question is that it will set the properties of Person type because it is the reference type and if you have some properties defined inside Employee then those will not be visible to its parent.



Reflection is used here and properties of the sub-class that are not present in the super-class will also be set. Try it out.
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Anupama is correct.
 
Jon Lee
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anupama Ponnapalli:


Reflection is used here and properties of the sub-class that are not present in the super-class will also be set. Try it out.



Yeah, I tried it out and it proves you are right, the properties of the sub-class are also set. The following is my testing code. It shows that the workID property of Employee class is also set!!!



[ March 18, 2007: Message edited by: Jon Lee ]

[ March 18, 2007: Message edited by: Jon Lee ]
[ March 18, 2007: Message edited by: Jon Lee ]
 
And then the flying monkeys attacked. My only defense was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic