<!--
* @author Abhijeet Kulkarni
* @version 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the Application : JSP XML Tutorial
* Creation/Modification History :
*
* Abhijeet Kulkarni 06-Jan-2003 Created
*
* Overview : This page is part of JSP XML tutorial. This page describes the
* features and sytax of jsp:useBean tag.
-->
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2">
<p>
<span class="about">
<![CDATA[ <jsp:useBean> Tag
</span>
<br/>
<br/>
<span class="paragraph">The <![CDATA[ <jsp:useBean> element locates or
instantiates a JavaBeans component. <![CDATA[ <jsp:useBean> first attempts to
locate an instance of the bean. If the bean does not exist, <![CDATA[ <jsp:useBean>
instantiates it from a class or serialized template. The body of a
<![CDATA[ <jsp:useBean>
element often contains a <![CDATA[ <jsp:setProperty> element that sets property
values in the bean. The body tags are only processed if <![CDATA[ <jsp:useBean>
instantiates the bean. If the bean already exists, the body tags have no
effect.</span>
<br/>
<br/>
<span class="about">JSP 1.2 XML syntax</span> <br/>
<table width="100%">
<tr>
<td bgcolor="#EEEEEE">
<pre>
<![CDATA[
<jsp:useBean id="beanInstanceName"
scope="page|request|session|application"
{
class="package.class" [ type="package.class" ] |
beanName="{package.class | %= expression %}"
type="package.class" |
type="package.class"
}
{ /> | < other elements </jsp:useBean> }
</pre>
</td>
</tr>
</table>
<p>
<span class="paragraph">
<b>Attributes and Usage</b>
</span>
<ul>
<li class="paragraph">
<b>id="beanInstanceName"</b>
<br/>
A variable that identifies the bean in the scope you specify. You can use the
variable name in expressions or scriptlets in the JSP page.The name is case
sensitive and must conform to the naming conventions of the scripting language
used in the JSP page. If the bean has already been created by another <jsp:useBean>
element, the value of id must match the value of id used in the original
element.</li>
<li class="paragraph">
<b>scope="page|request|session|application"</b>
<br/>
The scope in which the bean exists and the variable named in id is available.
The default value is page.</li>
<li class="paragraph">
<b>class="package.class"</b>
<br/>
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.</li>
<li class="paragraph">
<b>type="package.class"</b>
<br/>
If the bean already exists in the scope, gives the bean a data type other than
the class from which it was instantiated. The value of type must be a superclass
of class or an interface implemented by class. If you use type without class
or beanName, no bean is instantiated. The package and class name are case
sensitive.</li>
<li class="paragraph">
<b>class="package.class" type="package.class"</b>
<br/>
Instantiates a bean from the class named in class and assigns the bean the data
type you specify in type. The value of type can be the same as class, a
superclass of class, or an interface implemented by class. The class you
specify in class must not be abstract and must have a public, noargument
constructor. The package and class names you use with both class and type are
case sensitive.</li>
<li class="paragraph">
<b>beanName="{package.class | %= expression %}" type="package.class"</b>
<br/>
Instantiates a bean from a class, a serialized template, or an expression that
evaluates to a class or serialized template. When you use beanName, the bean is
instantiated by the java.beans.Beans.instantiate method. The Beans.instantiate
method checks whether the package and class you specify represents a class or
a serialized template.</li>
</ul>
</p>
<span class="about">Example using JSP 1.2 XML syntax</span> <br/>
<table width="100%">
<tr>
<td bgcolor="#EEEEEE">
<pre>
<![CDATA[
<jsp:useBean id="cart" scope="session" class="session.Carts" />
<jsp:setProperty name="cart" property="*" />
<jsp:useBean id="checking" scope="session" class="bank.Checking" >
<jsp:setProperty name="checking" property="balance" value="0.0" />
</jsp:useBean>
</pre>
</td>
</tr>
</table>
<br/>
<span class="about">Conventional JSP syntax</span>
<br/>
<table width="100%">
<tr>
<td bgcolor="#EEEEEE">
<pre>
<![CDATA[
<jsp:useBean id="beanInstanceName"
scope="page|request|session|application"
{
class="package.class" [ type="package.class" ] |
beanName="{package.class | <%= expression %>}"
type="package.class" |
type="package.class"
}
{ /> | < other elements </jsp:useBean> }
</pre>
</td>
</tr>
</table>
<br/>
<span class="about">An example using conventional JSP syntax</span>
<br/>
<span class="paragraph"> Please note that expressions in conventional JSP
syntax must be enclosed in <![CDATA[ <%=...%> construct</span>
<table width="100%">
<tr>
<td bgcolor="#EEEEEE">
<pre>
<![CDATA[
<jsp:useBean id="cart" scope="session" class="session.Carts" />
<jsp:setProperty name="cart" property="*" />
<jsp:useBean id="checking" scope="session" class="bank.Checking" >
<jsp:setProperty name="checking" property="balance" value="0.0" />
</jsp:useBean>
</pre>
</td>
</tr>
</table>
</p>
</jsp:root>