• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Standard action!!!

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all this is Amit m preparing for the SCWCD 1.4....

I am having one doubt.
This is from Head First jsp and Servlet page no. 360:
Bean class is defined like

package foo;
abstract class Person{
private String name = null;

public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name
}
}

public class Employee extends Person{
private int empID = 0;

public void setEmpID(int empID)
{
this.empID = empID;
}
public int getEmpID()
{
return empID;
}
}

And The standard action is
<jsp:useBean id =�person� type=�foo.Person� class=�foo.Employ�>
<jsp:setProperty name = �person� property=�*�/>
</jsp:useBean>:

in the standard action the type is person and the object is of type Employee, according to me if we will do

person.getEmpid();

it will not be accessible. It is written in the book that all the properties will be set by the container but how it will set all the properties if it not accessible.

Considering that input field in the HTML matches the property name:

Please let me know if I am wrong any where.
Thanking in advance.
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bean property name is derived by stripping the get and set and replacing the first character to lower case. So empId is the resultant property name.
If request parameter in the html matches this like

<input type="text" name="empId">


them the container will set the property with the value of the corresponding request parameter.

Can you be more precise with your question.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure if I understand your quwstion either. Even though the type is a Person object, it actually points to an Employee object, so the variables will be available. At least that's what I think.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the question Amit asked is quite clear . Since the reference is of type foo.Person the only setter method available will be

public void setName(String name)

The other setter method public void setEmpID(int empID) is not defined or declared in Person. So the only property that may be set is name.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great question. While reading this chapter, I went right past this example, looked at the next page which had both type and class as Employee and figured, it shouldn't be possible with polymorphism. however your question made me take notice. I tried this out and it infact works.

This is code which tomcat generated for the jsp ( i removed the package names from the generated source for clarity...both Employee and Person were in packages )




[ October 18, 2005: Message edited by: M Rama ]
[ October 18, 2005: Message edited by: M Rama ]
 
Amitkumar Dhama
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all Thanks for your great response....

Thanks Rama your answer is clear to me tomcat is typecasting it, that was the code generated by the tomcat now two questions are striking me right here...

1. Will the other servers take care of it.....
2. What are the cases in which tomcat or other server will do automatic typecasting.....

If all the servers are taking care of it, then no need toremember the polymorphism.

thanking i9n advance.....
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic