Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean type attribute problem

 
Rick Rangers
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm doing a test exam in preparation for my real exam next week
and given the following snippet:

<jsp:useBean id="cust" type="test.beans.CustomerBean" scope="session" />

The explanation of the question says that a CustomerBean instance is created if the attribute name cust is not found.

My book (Deshmukh) says that if you only specify a type and an object
cannot be located an InstantiatonException will occur. Which one
is correct? Deshmukh makes more sence to me because if the type would be an interface then you can't instantiate an object, right?
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,

you are correct. if useBean with type attribute the object (which set to id att.) must be in the specified scope.

useBean with class att. creats a new object if that is not in the scope.

You can test this by writng simple code.
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry,

i made a mistake, the scope specifies where we create the new object..

but now i have a question,

what is the usefullness of scope att. with type att. (without class att.)? because we cant create new object. so i think that is meaningless only type and scope atts.

can other make clear this?
 
Rick Rangers
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use both the type attribute and scope attribute you specify
in which scope the bean referenced by a variable of type "type" should
be searched.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic