wood burning stoves*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Understanding Errors in creating a bean. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Understanding Errors in creating a bean." Watch "Understanding Errors in creating a bean." New topic
Author

Understanding Errors in creating a bean.

Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Hi there!

I have been playing with this code , but I am not sure about some of the results I got.
If some one could help me with that .. that would be great!

Person File :


Employee File :



And finally PrintBean.jsp



I change the <jsp:useBean id="person" class="foo.Employee" type="foo.Person" scope="page">
to get different results.


1) class="foo.Person" The value for the useBean class attribute foo.Person is invalid
- I dont get this. Even if I dont mention EmpId which is not accessible to the person instance even then i get the same error.And the Person class is not even Abstract

2)type= "foo.Person" Cannot find any information on property 'empId' in a bean of type 'foo.Person'
-This makes sense as it cannt access EmployeeId

3)type="foo.Employee" bean person not in scope
- What exactly do you mean by "bean is not in scope"

4)class="foo.employee" works fine
-Makes sense.Creates an instance of type employee

5)class="foo.Person" type="foo.Person" The value for the useBean class attribute foo.Person is invalid
-Not sure about this one.

6)class="foo.Employee" type="foo.Employee" works fine
Reference n object of type Employee .ok!

7)class="foo.Employee" type="foo.Person" works fine
Reference of Person.Object of Employee.Ok!

8)class="foo.Person" type="foo.Employee" The value for the useBean class attribute foo.Person is invalid
Cannot have refernce of the child class.ok!


Can some one explain thee reason for the other errors i didnot get.
Also,i am not sure the significance of the scope and its use. How can I test code to understand the difference between the difference scopes.


The future belongs to those who believe in the beauty of their dreams.Dream BIG!
vani venkat
Ranch Hand

Joined: Nov 21, 2006
Posts: 142
3)type="foo.Employee" bean person not in scope
- What exactly do you mean by "bean is not in scope"



if you use type without class attribute, this Employee bean must already present in specified scope. so, in servlet from which you are dispatching request, instance of employee bean must be added in page scope.
foo.Employee emp = new foo.Employee();
//setters of elements of emp
pageContext.setAttribute("person",emp);

This will make sure that person bean is in scope(page), and getAttribute uses this person bean.


SCJP 1.4, SCWCD 1.5
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Is there any way using scriptless JSP to find out if a bean exists or not..?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Nabila Mohammad wrote:Is there any way using scriptless JSP to find out if a bean exists or not..?

${empty person} will return true is person is null (does not exist). You can use it in JSTL c:if tag's test attribute.


[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Understanding Errors in creating a bean.
 
Similar Threads
Request to Bean
examulator question error
Whats the error???
doubt in scriptless JSPs
jsp:useBean tag query.