• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ Bean related standard actions question

 
Jared Sprague
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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 ]
 
Sami Sayeed
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic