Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Understanding Errors in creating a bean.  RSS feed

 
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way using scriptless JSP to find out if a bean exists or not..?
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!