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

Usage of type and class attribute in jsp:useBean

 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What are the situations when we use type and class attributes in jsp:useBean tag.
With regards,
Padma priya N.G.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You usually use "class" when you want a new instance to be generated if the container found no existing instance of the bean.
 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
But, why are they used in a combined way?
With regards,
Padma priya N.G.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's consider a Person class, and its Employee subclass. You could use both "type" and "class" to say : I'm expecting a Person, but if there's none, make an Employee for me.
 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Do you use like this?

jsp:useBean id="someAttribute1" class="Person" type="Employee"
With regards,
Padma priya N.G.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Padmapriya,

Please have a look at the syntax and description here .

Just listing out the points for both "class" and "type" attributes below.

  • class="package.class"

  • Instantiates a Bean from a class, using the new keyword and the class constructor. The class must not be abstract and must have a public, no-argument constructor. The package and class name are case sensitive.

  • type="package.class"

  • If the Bean already exists in the scope, gives the Bean a data type other than the class from which it was instantiated. If you use type without class or beanName, no Bean is instantiated. The package and class name are case sensitive.

    Precisely,

  • type -> just to pick up an existing instance if any of the same type
  • class -> to instantiate an instance of the class if it does NOT exist.



  • HtH.
    [ July 23, 2007: Message edited by: Raghavan Muthu ]
     
    Padma priya Gururajan
    Ranch Hand
    Posts: 437
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Raghavan,
    Can you give a example for this?
    With regards,
    Padma priya N.G.
     
    Christophe Verré
    Sheriff
    Posts: 14691
    16
    Eclipse IDE Ubuntu VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    No, the other way around :
     
    Padma priya Gururajan
    Ranch Hand
    Posts: 437
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,
    Thanks.
    With regards,
    Padma priya N.G.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic