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

beanName

 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the beanName attribute of the useBean standard action do?

i.e
<jsp:useBean id="myBean beanName="notSure" type="package.class"/>

This is one topic that I don't believe is covered in HeadFirst
 
Sanjay pts
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are right and so many question will be asked on this topic itself.

-Sanjay
 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well that is help full

THe Spec says" The name of a bean, as expected by the instantiate method
of the java.beans.Beans class.
This attribute can accept a request-time attribute expression
as a value."

But what does that mean?
 
AmitKumar Jain
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These lunes are from jsp2.0 spec.....

The jsp:useBean action...
It is also possible to use this action to give a local name to an object defined elsewhere, as in another JSP page or in a servlet. This can be done by using the type attribute and not providing class or beanName attributes.
At least one of type and class must be present, and it is not valid to provide both class and beanName. If type and class are present, class must be assignable to type (in the Java platform sense). For it not to be assignable is a translationtime error.
The attribute beanName specifies the name of a Bean, as specified in the
JavaBeans specification. It is used as an argument to the instantiate method in the java.beans.Beans class. It must be of the form a.b.c, which may be either a class,or the name of a resource of the form a/b/c.ser that will be resolved in the current ClassLoader. If this is not true, a request-time exception, as indicated in the semantics of the instantiate method will be raised. The value of this attribute can be a request-time attribute expression.

From the above bold lines, I come to the conclusion the beanName is same as the class attribute, and the only difference being "The value of beanName attribute can be a request-time attribute expression"

I hope my interpretation is correct. What do the other ranchers say?
 
AmitKumar Jain
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I add to my earlier discussion....
Again I quote the lines from jsp2.0 spec....

6. If the object(specified by id) is not found in the specified scope, and the class specified names a non-abstract class that defines a public no-args constructor, then the class is instantiated. The new object reference is associated with the scripting variable and with the specified name in the specified scope using the appropriate scope dependent association mechanism (see PageContext). After this, step 8 is performed.
If the object is not found, and the class is either abstract, an interface, or no public no-args constructor is defined therein, then a java.lang.InstantiationException shall occur. This completes the processing of this jsp:useBean action.

7. If the object is not found in the specified scope; and beanName is given, then the method instantiate of java.beans.Beans will be invoked with the ClassLoader of the servlet object and the beanName as arguments. If the method succeeds, the new object reference is associated the with the scripting variable and with the specified name in the specified scope using the appropriate scope dependent association mechanism (see PageContext).

Hence if id and class is given,(case6) the process of creation of object is different than in the case when id and beanName is given(case7)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic