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.
![]() |
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:
To edit the properties of an existing tag scripting variable:
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
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 |