• 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

HFSJ Bean related standard actions question

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a question on page 360 of HFSJ.
The question is regarding this code:
HTML


JSP



I understand that this is supose to iterate over the beans properties and find any matches and set them to the value of the matching request parameter, but I don't see how this can work because somewhere the traslated code is going to try and set the empID on a Person type reference which wont work because setEmpID() is not defined in the Person type. Can anyone explain this to me?
Thank you!
[ November 29, 2004: Message edited by: Jared Sprague ]
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

whenever we user type and class in the method
and if the bean is not available in the defined scope of the jsp:useBean,
The bean shall be instantiated by the container.
So if we use something like this.

<jsp:useBean id="person" type="foo.Person" class="foo.Employee"> <jsp:setProperty name="person" property="*" /></jsp:useBean>
The code in the jsp would be..
foo.Person person = new foo.Employee();
Now when the setProperty is called the Parameters of the form fields are matched for the attributes in the class but the mutator methods are used.

for example,
the form has empID defined in the Employee class so,
the setEmpID will be called on the person(object).
As you know the methods are called based on the constructor used and not on the type of the Object,
I hope I have helped in understanding the concept.
cheers
SCJP,SCWCD1.4
Sami
 
Jared Sprague
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correct me if I'm wrong, but if setEmpID() is only defined in the Employee class and not the parent Person class then this should not work:

This won't complie because setEmpID() is not defined in Person, right?

[ November 30, 2004: Message edited by: Jared Sprague ]
[ November 30, 2004: Message edited by: Jared Sprague ]
 
Jared Sprague
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My last post was a rhetorical question, because I already know the answer.
The methods that you can call are based on the REFERENCE type not the object that is instantiated. And because of this I don't believe that this code sample from the book on page 360 can work, because it would involve calling setEmpID() on Person. Can anyone prove me wrong?
 
reply
    Bookmark Topic Watch Topic
  • New Topic