Adding Scripting Variables

Your custom tags can define scripting variables that are accessible to your Java Server Pages. In fact, you can even get the JSP engine to add a Java variable to the generated servlet to hold the value of your script variable. All you need to do is create a special TagExtraInfo class that describes the scripting variables your tag can define.

Listing 16.28 shows a subclass of TagExtraInfo that defines a scripting variable called scriptVar.

Code Listing 16.28. Source Code for ScriptExtraInfo.java
 import javax.servlet.jsp.tagext.*; public class ScriptExtraInfo extends TagExtraInfo { public VariableInfo[] getVariableInfo(TagData data) { return new VariableInfo[] { new VariableInfo("scriptVar", "java.lang.String", true, ...

Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.