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 Hans Bergsten <ha...@gefionsoftware.com> on 2000/10/12 06:06:30 UTC

Re: is it possible to use a tag that defines a scripting variable multiple times in a page?

Richard Sand wrote:
> 
> Yes but if I want to use it as a scripting variable in the page outside of
> my tags then I have to use a TEI to define it at translation time.  And I
> tried using a TEI with declare=true and declare=false and it won't work
> either way....
> 
> Unless I'm missing something?
> 
> -Richard

A possible solution is to define two optional attributes for the custom
action: "id" and "name", both used to specify the name of the bean the
same as in <jsp:useBean> and e.g. <jsp:getProperty>. Use "id" if you want 
to create the bean, use "name" when you want to access (and possibly replace) 
an existing bean. In your TEI you can find out which attribute is used and 
set "declare" to the appropriate value.

Hans

> ----- Original Message -----
> From: <ro...@elastica.com>
> To: <ta...@jakarta.apache.org>
> Sent: Wednesday, October 11, 2000 8:21 PM
> Subject: Re: is it possible to use a tag that defines a scripting variable
> multiple times in a page?
> 
> > Isn't declaring the variable just you putting it into the page scope if
> > it's not already there?
> >
> > On Wed, 11 Oct 2000, Richard Sand wrote:
> >
> > > Hi all,
> > >
> > > I'm trying to write a tag that uses a bean that I've written.  I want
> the tag to look for the bean in the page context, and if its not there, make
> one and add it to the page.  I want to be able to use the tag in multiple
> places, and use the bean it creates elsewhere in the page.
> > >
> > > But this last requirement seems to be a hitch.  i.e., consider the
> following in a jsp page:
> > >
> > > <mytags:tag1/>           // this tag creates a bean with an id=mybean
> > > stuff.....
> > > <mytags:tag1/>          // this bean sees that id=mybean already exists
> and reuses it
> > > more stuff......
> > > <% if (mybean.somemethod() == true {....         // this code snippet
> uses mybean
> > >
> > > Is this possible? If I write a TEI that defines mybean and has
> declare=true, then I get a compile error because mybean is defined twice.
> If I have it set to false, I get an error for it being undeclared, even with
> only a single use of mytags and no references to mybean.
> > >
> > > Am I missing something?  Can someone tell me how this can work?  Is
> there a way to tell a JSP page that this tag will: "declare a variable if
> its not already declared in the page"
> > >
> > > Thanks!
> > >
> > > -Richard
> > >
> >


-- 
Hans Bergsten		hans@gefionsoftware.com
Gefion Software		http://www.gefionsoftware.com