tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Morgan Delagrange <>
Subject Re: exposing script variables
Date Tue, 24 Apr 2001 23:06:48 GMT
(Pierre sent a related response as I was typing this, but I think it's
still helpful.)

Ah, OK, I think I see what you're asking for now.  Often when people
talk about scripting variables, they're just talking about assigning
attributes, but you want the real deal.  OK, time to introduce you to the
glories of TagExtraInfo, a very nifty but slightly magical detail
of the Servlet spec.

You'll need to write a javax.servlet.jsp.tagext.TagExtraInfo class that
describes the name of your scripting variable, what type of object it
contains, and its scope on the page.  In your case, if you just want
to assign it's probably something like this:

public class DefineTEI extends TagExtraInfo {

  public final VariableInfo[] getVariableInfo(TagData data)
    return new VariableInfo[]
      new VariableInfo(

See that VariableInfo object that I defined?  The first part retrieves the
value of the id attribute, so that the container knows how to create the
scripting variable.  The second part indicates what type of Object your
scipting variable will contain (in your case, java.lang.Object).  The
third part is true (just ignore it).  And the fourth part tells the
servlet container where to make the scripting variable available.  You
probably want AT_END, meaning after the end tag of your custom tags.  The
other options are AT_BEGIN (after the begin tag) and NESTED (only between 
the begin and end tags).

Then, you have to go to your TLD file and indicate that this class is
the extra info for your tag, something like this:


If you do this, then the following tag:

  <itl:define id="organizationsBean" scope="session"/>

should take your attribute and assign it as a scripting variable (using
the logic of findAttribute(String), I believe), so you can treat it as if
it we're already defined on the page:

  <% String organizationId =
((OrganizationsBean) organizationsBean).getColumn("ORGANIZATIONID"); %>

Is this what you're looking for?

- Morgan

View raw message