Create a new attribute (in the scope specified by the
toScope
property, if any), and a corresponding scripting
variable, both of which are named by the value of the id
attribute. The corresponding value to which this new attribute (and
scripting variable) is set are specified via use of exactly one of the
following approaches (trying to use more than one will result in a
JspException being thrown):
name
attribute (plus optional
property
and scope
attributes) -
The created attribute and scripting variable will be of the type of the
retrieved JavaBean property, unless it is a Java primitive type,
in which case it will be wrapped in the appropriate wrapper class
(i.e. int is wrapped by java.lang.Integer).value
attribute - The created attribute and
scripting variable will be of type java.lang.String
,
set to the value of this attribute.java.lang.String
, set to
the value of the nested body content.If a problem occurs while retrieving the specified bean property, a request time exception will be thrown.
The <bean:define>
tag differs from
<jsp:useBean>
in several ways, including:
value
attribute.<jsp:setProperty>
tags) that are only executed
if a bean was actually created.
USAGE NOTE - There is a restriction in the JSP 1.1
Specification that disallows using the same value for an id
attribute more than once in a single JSP page. Therefore, you will not
be able to use <bean:define>
for the same bean
name more than once in a single page.
USAGE NOTE - If you use another tag to create the body content (e.g. bean:write), that tag must return a non-empty String. An empty String equates to an empty body or a null String, and a new scripting variable cannot be defined as null. Your bean must return a non-empty String, or the define tag must be wrapped within a logic tag to test for an empty or null value.
USAGE NOTE - You cannot use bean:define to instantiate a DynaActionForm (type="org.apache.struts.action.DynaActionForm") with the properties specified in the struts-config. The mechanics of creating the dyna-properties is complex and cannot be handled by a no-argument constructor. If you need to create an ActionForm this way, you must use a conventional ActionForm.
See the Bean Developer's Guide section on bean creation for more information about these differences, as well as alternative approaches to introducing beans into a JSP page.