• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

useBean type attribute??

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

What happens when we just say

<jsp:useBean id="person" type="foo.Person" scope="page" />

In the HFSF, they say it works perfectly fine provided if the person attribute already exists in "page" scope. What it means???I'm not understanding. Can anyone help me what they really meant here??

Thanks in advance.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use the "class" attribute, the class specified there will be instaintiated using the public no arg constructor, if the attribute in request, page, or session, or application scope does not exist.

When you use the "type" attribute, you better make sure that the attribute is already available in the scope you specify. If its not available... KABOOM !
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,

So that means, with only the type defined in the useBean tag, we are telling the container that use the reference specified in the type wherein the object is already available as an attribute??? Am I confusing myself???
 
Boobalan Pillai
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right..with type attribute object should be already exist in any one of the scope...because type would be an interface or abstract ,you cannt create object for that if the corresponding class type does not exist...

regards
Bala.
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If no existing bean matches the type, no new bean instance will be created and an InstantiationException is thrown.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic