Creating and Editing Scripting Variables

See Also

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. You use the Add Tag Scripting Variable dialog box to add variable elements to a tag entry in a TLD file. You can edit the properties of variable element using the Tag Scripting Variable Customizer or you can open the TLD file in the Source Editor. When you use the Generate Tag Handlers action on the tag, the IDE creates template code for the variable in the generated Java source file.

warning  Only TLD files that conform to JSP 1.1 or 1.2 specifications can be edited in the customizer. Other versions are treated as XML files and must be edited in the Source Editor.

To add a tag scripting variable to the TLD file:

  1. In the Filesystems window, right-click the tag element and choose Add Scripting Variable from the contextual menu.
  2. In the Add New Tag Scripting Variable dialog box, specify the properties of the scripting variable. See Tag Scripting Variable Information later in this topic.
  3. Click OK.

To edit the properties of an existing tag scripting variable:

  1. In the Filesystems window, right-click the scripting variable and choose Customize from the contextual menu.
  2. In the Tag Scripting Variable Customizer, edit the scripting variable properties.
  3. 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

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:myIterator>
<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";
}
See Also
Creating and Editing Tags
Creating and Editing Tag Attributes
Generating Java Source Tag Handlers

Legal Notices