• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Polymorphism of the jsp:useBean

 
Jon Lee
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • 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?

 
Manju Devarla
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sets the properties of both as its property="*"
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I am with Ali, I will try to test it using real code...
 
Anupama Ponnapalli
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • 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.
 
Tridib Samanta
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Anupama is correct.
 
Jon Lee
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic