Correct way to handle optional attributes in JSP custom tag handler

Discussion in 'Java' started by Bruce Atherton, Jan 14, 2004.

  1. I'm having a problem porting an application from Weblogic 5.1 to
    Oracle 9.04. It has custom tags that have optional parameters. The
    trouble is that it appears that the web app is reusing the tag handler
    classes.

    The current code looks something like this:

    public class MyTag extends TagSupport {
    private String optional = "not set";

    public MyTag() {
    super();
    }

    public void setOptional(String optional) {
    this.optional = optional;
    }

    public int doStartTag() throws JspTagException {
    pageContext.getOut().print(optional);
    return SKIP_BODY;
    }
    }

    The trouble is that sometimes, in JSPs that don't define the
    "optional" attribute, the output reflects the value from a previous
    instantiation of the tag. Not every time, but occasionally.

    It looks likely that this is happening because the app server is doing
    some caching. So I have two questions:

    1. Specifically, does anyone know how to turn this behaviour off in
    Oracle App Server 9.04 (standalone, not with the webcache package).

    2. More generally, what is the correct way to instantiate default
    values for optional attributes. Does the spec require that the
    release() method reset all optional values to their default values? If
    so, what happens when there are two tags on the same page, one with
    optional and one not. Or should it be reset at the end of doEndTag().
    If so, what happens if an app server tries to reuse the same tag
    without calling the set methods, because it thinks they are the same
    (can they do that?).

    Any information appreciated. Thanks.
    Bruce Atherton, Jan 14, 2004
    #1
    1. Advertising

  2. > I'm having a problem porting an application from Weblogic 5.1 to
    > Oracle 9.04. It has custom tags that have optional parameters. The
    > trouble is that it appears that the web app is reusing the tag handler
    > classes.


    Just in case anyone reading this has a similar problem, I thought I
    would post the solution.

    At first, it looked like adding the attribute 'jsp-cache-tlds="false"'
    to the orion-web-app tag in the global-web-applications.xml file would
    solve the problem. It didn't. The right answer was to add the
    following lines to the <servlet-name>jsp</servlet-name> section:

    <init-param>
    <param-name>tags_reuse_default</param-name>
    <param-value>none</param-value>
    </init-param>

    That did the trick.

    As for the question about the general procedure to follow, I think we
    are probably doing the right thing. This looks like a hack to work
    around a bug, to me.
    Bruce Atherton, Jan 15, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jstack
    Replies:
    1
    Views:
    606
    Tor Iver Wilhelmsen
    Jul 4, 2003
  2. Crowther
    Replies:
    0
    Views:
    3,901
    Crowther
    Nov 19, 2003
  3. Lukasz Indyk
    Replies:
    1
    Views:
    1,472
    Andrew Thompson
    Sep 22, 2004
  4. shruds
    Replies:
    1
    Views:
    792
    John C. Bollinger
    Jan 27, 2006
  5. sugapablo
    Replies:
    0
    Views:
    2,153
    sugapablo
    Sep 21, 2007
Loading...

Share This Page