Correct way to handle optional attributes in JSP custom tag handler

B

Bruce Atherton

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.
 
B

Bruce Atherton

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top