JSP.5.5 Scripting Variables


JSP.5.5 Scripting Variables

The JSP specification supports scripting variables that can be declared within a scriptlet and can be used in another. The actions in a JSP page also can be used to define scripting variables so they can be used in scripting elements, or in other actions; for example, the jsp:useBean standard action may define an object which can later be used through a scripting variable.

Since the logic that decides whether an action instance will define a scripting variable may be quite complex, this information is not encoded in the Tag Library Descriptor directly; rather, the name of a TagExtraInfo class is given in the TLD and the getVariableInfo method is used at translation time to obtain information on each variable that will be created at request time when this action is executed. The method is passed a TagData instance that contains the translation-time attribute values.

The result of the invocation on getVariableInfo is an array of VariableInfo objects. Each such object describes a scripting variable by providing its name, its type, whether the variable is new or not, and what its scope is. Scope is best described through a picture (Figure JSP.5-1).

Figure JSP.5-1. Scope of Scripting Variables

The defined values for scope are:

  • NESTED , if the scripting variable is available between the start tag and the end tag of the action that defines it.

  • AT_BEGIN , if the scripting variable is available from the start tag of the action that defines it until the end of the page.

  • AT_END , if the scripting variable is available after the end tag of the action that defines it until the end of the page.

The scope value for a variable implies what methods may affect its value and thus, in lack of additional information, where synchronization is needed:

  • For NESTED , after doInitBody and doAfterBody for a tag handler implementing BodyTag , and after doStartTag otherwise .

  • For AT_BEGIN , after doInitBody, doAfterBody, and doEndTag for a tag handler implementing BodyTag , and doStartTag and doEndTag otherwise.

  • For AT_END , after doEndTag method.



Java 2 Platform, Enterprise Edition. Platform and Component Specifications
Java 2 Platform, Enterprise Edition: Platform and Component Specifications
ISBN: 0201704560
EAN: 2147483647
Year: 2000
Pages: 399

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net