• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Polymorphism of the jsp:useBean  RSS feed

 
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?

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sets the properties of both as its property="*"
 
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...
 
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.
 
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 ]
 
Danger, 10,000 volts, very electic .... tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!