Creating and Editing Scripting Variables
See Also
Use the Add Tag Scripting Variable dialog box to create scripting variables and
the Tag Scripting Variable Customizer to edit the properties of scripting variables.
A scripting variable is a value that a tag exports to a JSP page. This value can
then be used in a scriptlet or an expression.
To add a tag scripting variable:
- In the Filesystems window, right-click the tag element and choose Add Scripting
Variable from the contextual menu.
- In the Add New Tag Scripting Variable dialog box, specify the properties
of the scripting variable. See Tag Scripting Variable Information.
- Click OK.
To edit the properties of an existing tag scripting variable:
- In the Filesystems window, right-click the scripting variable tand choose
Customize from the contextual menu.
- In the Tag Scripting Variable Customizer, edit the scripting variable properties.
- Click OK to have the changes take effect immediately and dismiss the Tag
Scripting Variable Customizer, or click Apply to apply the changes without
dismissing the dialog box.
Once a Tag Scripting Variable Customizer is displayed, it tracks the selection
and shows the properties of any variable that is selected.
Tag Scripting Variable Information
- Variable Name. Specifies the name of the variable that appears in
the Explorer. This name is used to manipulate the variable, but can sometimes
be the scripting variable name as well. The default value is newVariable<n>,
where <n> can be blank or can be an integer that makes the
variable name unique.
- Fixed. Specifies that the name of the variable is fixed and comes
from the Variable Name. Note that if multiple tags using this type of scripting
variable appear in a JSP page, the value of the variable can be overwritten.
See examples.
- From Attribute. Specifies that the name of the variable taken from
the runtime value of the attribute you enter or choose from the list. See
examples.
- Other. Specifies that the name of the variable is not fixed or derived
from an attribute. You must write methods in the Tag Handler and
Tag Extra Info classes that determine the name of the variable. See
examples.
- Variable Type. Specifies the variable type. Choose a standard type
from the list in the combo box, or enter a Java class name.
- Scope. Determines the lifetime of the variable. Possible values are
NESTED, AT_BEGIN, or AT_END. The default is NESTED.
- New Declaration. Specifies a new declaration. The default is checked.
Examples
This example shows the declaration of a scripting variable with a fixed name,
user. Scope is set to AT_END.
<log:login username="bob234"/>
...
<%=user%>
This example shows a scripting variable in which the name is derived from an
attribute.
<tags:myIterator n="10" iterVar="i">
...
<%=i%>:
<tags:myIterator n="<%=i%>" iterVar="j">
<%=j%>
</tags:Iterator>
<BR>
</tags:myIterator>
This example shows the scripting variable
numResults,
declared on the query tag. Names are based on the value of the Other property on the
Query tag.
<db:myQuery id="foo">
select * from bigtable3
</db:myQuery>
<TABLE>
<db:reiterate n= "<%=foo_numResults%>
source="<%Foo_results>%"
<TR><TD>...table cell...</TD></TR>
</db:reiterate>
</TABLE>
Here is the code to implement the two variables' names in
QueryTag.java.
public java.lang.String setNameOfVariable_results() {
return getId() + "Results";
}
public java.lang.String setNameOfVariable_numResults() {
return getId() + "NumResults";
}
For more information about creating and using scripting variables, see JavaServer
Pages Specification, available at http://java.sun.com/products/jsp.
Legal Notices