You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by James Dasher <jf...@thermopylae.com> on 2001/12/28 18:08:38 UTC

Init-Params for a Custom Tag Library.

Is there a way to set the default value of a field within a custom
taglib declaratively (propertyfile, initParam, etc.)?  
What I am looking for here is something like an init-param--I do _not_
want to have to pass it in as an attribute every time I use the tag.

For a concrete example:

public class ExampleTag extends TagSupport {
  private String foo="bar";
  public int doStartTag() {
    try {
      JspWriter out = pageContext.getOut();
      out.print(foo);
    } catch(IOException e) {e.printStackTrace();}
  }
    return(SKIP_BODY);
  }
}

Imagine I want to set String foo to something other than "bar", for all
instances of ExampleTag within this particular webapp.  I do not want to
have to pass it in as a parameter.

What is the appropriate, approach?

So far I have looked at setting a ServletContext InitParameter as one
possible way to do it, and reading the value from the Context in an
instance initializer block, but this gives me a namespace-pollution kind
of vibe.

I have thought about reading from a propertyfile in an instance
initializer, but I do not know how much overhead propertyfile reads
incur.

I have thought about a static initializer, but this means that the
then-static property values would work across _all_ webapps in a
container.  Undesirable.

Can someone enlighten as to what the "right way" to do this is?


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Init-Params for a Custom Tag Library.

Posted by cr...@crazybob.org.
I would usually use an environment entry in the web.xml. I would write my code so that if the environment entry is not found, it will default to "bar".

Hope this helps,
Bob


On Fri, Dec 28, 2001 at 12:08:38PM -0500, James Dasher wrote:
> Is there a way to set the default value of a field within a custom
> taglib declaratively (propertyfile, initParam, etc.)?  
> What I am looking for here is something like an init-param--I do _not_
> want to have to pass it in as an attribute every time I use the tag.
> 
> For a concrete example:
> 
> public class ExampleTag extends TagSupport {
>   private String foo="bar";
>   public int doStartTag() {
>     try {
>       JspWriter out = pageContext.getOut();
>       out.print(foo);
>     } catch(IOException e) {e.printStackTrace();}
>   }
>     return(SKIP_BODY);
>   }
> }
> 
> Imagine I want to set String foo to something other than "bar", for all
> instances of ExampleTag within this particular webapp.  I do not want to
> have to pass it in as a parameter.
> 
> What is the appropriate, approach?
> 
> So far I have looked at setting a ServletContext InitParameter as one
> possible way to do it, and reading the value from the Context in an
> instance initializer block, but this gives me a namespace-pollution kind
> of vibe.
> 
> I have thought about reading from a propertyfile in an instance
> initializer, but I do not know how much overhead propertyfile reads
> incur.
> 
> I have thought about a static initializer, but this means that the
> then-static property values would work across _all_ webapps in a
> container.  Undesirable.
> 
> Can someone enlighten as to what the "right way" to do this is?
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>