Java Reference
In-Depth Information
</managed-bean>
<managed-bean>
<managed-bean-name>addressBean</managed-bean-name>
<managed-bean-class>
com.example.mybeans.AddressBean
</managed-bean-class>
<managed-bean-scope> none </managed-bean-scope>
<managed-property>
<property-name>street</property-name>
<null-value/>
<managed-property>
...
</managed-bean>
The first
CustomerBean
declaration (with the
managed-bean-name
of
custom-
er
) creates a
CustomerBean
in request scope. This bean has two properties,
mail-
ingAddress
and
streetAddress
. These properties use the
value
element to ref-
erence a bean named
addressBean
.
The second managed bean declaration defines an
AddressBean
, but does not create
it, because its
managed-bean-scope
element defines a scope of
none
. Recall that
a scope of
none
means that the bean is created only when something else references it.
Because both the
mailingAddress
and the
streetAddress
properties reference
addressBean
using the
value
element, two instances of
AddressBean
are created
when
CustomerBean
is created.
When you create an object that points to other objects, do not try to point to an object with
a shorter life span, because it might be impossible to recover that scope's resources when
it goes away. A session-scoped object, for example, cannot point to a request-scoped ob-
ject. And objects with
none
scope have no effective life span managed by the framework,
connections.