Customizing Scripting Variables

See Also

Use the Add Tag Scripting Variable dialog box to create new 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:

  1. In the Explorer, right-click the tag element to which you want to add a scripting variable.
  2. Choose Add Scripting Variable from the contextual menu.
  3. In the Add New Tag Scripting Variable dialog box, specify the properties of the scripting variable. See Tag Scripting Variable Information.
  4. Click OK to have the changes take effect immediately and dismiss the Add New Scripting Variable dialog box.

To edit the properties of an existing tag scripting variable:

  1. In the Explorer, right-click the scripting variable to be edited.
  2. Choose Customize from the contextual menu.
  3. In the Tag Scripting Variable Customizer, edit the scripting variable properties.
  4. 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.

Alternatively,

Tag Scripting Variable Information

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, Version 1.2 available at http://java.sun.com/products/jsp.

See Also
Customizing Tag Attributes
Generating Tag Handlers

Legal Notices