This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Standard action!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Standard action!!!" Watch "Standard action!!!" New topic
Author

Standard action!!!

Amitkumar Dhama
Ranch Hand

Joined: Feb 14, 2005
Posts: 56
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.


SCJP 1.4, SCWCD 1.4, M.Tech(CSE)
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
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.


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
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.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Atul Chandran
Greenhorn

Joined: Oct 24, 2004
Posts: 22
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.
M Rama
Ranch Hand

Joined: Mar 04, 2005
Posts: 91
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

Joined: Feb 14, 2005
Posts: 56
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.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Standard action!!!
 
Similar Threads
EL and jsp:usebean..type/class
Standard actions - doubt in HFS - page 414
Scriptless JSPs
Concrete class problem in EL
jsp:useBean exception