You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Peter Alfors <pe...@irista.com> on 2001/05/21 15:49:04 UTC

[Fwd: Re: exposing script variables]

Thomas,

  I think that this might help.

Pete

-------- Original Message --------
Subject: Re: exposing script variables
Date: Wed, 25 Apr 2001 09:20:02 -0500
From: Peter Alfors <pe...@irista.com>
Reply-To: taglibs-user@jakarta.apache.org
Organization: HK Systems, Inc
To: taglibs-user@jakarta.apache.org
References: <Pi...@localhost>

Pierre, Morgan:

Thank you VERY much!  That is exactly what I needed.

Pete


Morgan Delagrange wrote:

> (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(
>                       data.getAttributeString("id"),
>                       "Object",
>                       true,
>                       VariableInfo.AT_END
>                       ),
>     };
>   }
> }
>
> 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:
>
>   <tag>
>     <name>define</name>
>     <tagclass>package.classname</tagclass>
>     <teiclass>package.DefineTEI</teiclass>
>     <bodycontent>empty</bodycontent>
>     <attribute>
>       <name>id</name>
>       <required>true</required>
>       <rtexprvalue>false</rtexprvalue>
>     </attribute>
>     <attribute>
>       <name>scope</name>
>       <required>false</required>
>       <rtexprvalue>false</rtexprvalue>
>     </attribute>
>   </tag>
>
> 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