File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Polymorphism and useBean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Polymorphism and useBean" Watch "Polymorphism and useBean" New topic
Author

Polymorphism and useBean

bernard savary
Ranch Hand

Joined: Jan 09, 2008
Posts: 91
Hi ,
I have a abstract super class called Person with no fields and a concrete subclass with name field . I use the following code in jsp:
<jsp:useBean id="emp" type="com.example.Person" class"com.example.Employee"/>
<jsp:setProperty name="emp" property="name" value="bernard" />
<jsp:getProperty name="emp" property="name"/>

The above works well . But in HFS they mention we can get and set properties that exist for the type and normal java polymorphism applies.
But when I try it is different and the generated source code has a call to some introspect... method . Can someone help to clarify this .
bernard savary
Ranch Hand

Joined: Jan 09, 2008
Posts: 91
Guys ,

Anybody has tired this yet ? I guess there is a realistic chance of this kind of questions to appear in the exam .
Dan Walin
Ranch Hand

Joined: Nov 11, 2003
Posts: 109
If Person has no fields, I'm not sure what properties you would be setting or getting in the type. I'd like to try this out but it seems like Person should have fields for this example to make sense.
bernard savary
Ranch Hand

Joined: Jan 09, 2008
Posts: 91
Hi Dan,
Sure It works! I tried it . Its contradictory to what Head first mentions in bullet points page144 .
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
would you please publish the 2 classes?

Thank you
bernard savary
Ranch Hand

Joined: Jan 09, 2008
Posts: 91
public abstract class Person {
}

public class Employee extends Person {
private String name ;
public String getName(){
return name;
}
public void setName(String n){
name= n ;
}
}
Dan Walin
Ranch Hand

Joined: Nov 11, 2003
Posts: 109
I must be missing something. Shouldn't Person have at least a method or something? I'm not really sure what is being extended since there's nothing really there. I'm not able to be of much help but I am interested if this is something that could potentially appear on the exam.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Polymorphism and useBean