Custom tag library - some attributes working, others not

[nobr]I have a custom tag library that I am trying to pass a parameter to. Some parameters can be passed but others can not. This is a really simplified example:

<%@ taglib uri="/taglib/blah.tld" prefix="blah" %>

<blah:simple selectid="<%=new Date().toGMTString()%>"/>

returns

23 Jul 2007 22:11:42 GMT

<blah:simple selectid="<%=request.getAttributeNames().toString()%>"/>

returns

java.util.Vector$1@e5d9d2

But when ido something likethis:

<blah:simple selectid="<%=((NameBean)request.getAttribute("NameBean")).getFname()%>"/>

the jsp returns

<blah:simple selectid="Jeff"/>

The name is right but I want to evaluate the expression not just display a tag.

My workaround is todothis:

<%

String myname =((NameBean)request.getAttribute("NameBean")).getFname()

%>

<blah:simple selectid="<%= myname %>"/><br>

which returns the correct value ... Jeff

I don't see a difference in these two expressions.

my tld is defined like this:

...

<tag>

<name>simple</name>

<tagclass>com.mycompany.blahtag </tagclass>

<bodycontent>empty</bodycontent>

<info></info>

<attribute>

<name>selectid</name>

<required>true</required>

<rtexprvalue>true</rtexprvalue>

</attribute>

</tag>

...

Any thoughts? I am using jdk 1.4x and weblogic 8?[/nobr][/nobr]

[1912 byte] By [jeff_chisma] at [2007-11-27 11:29:22]
# 1

The difference: one uses quotes in the expression, the other doesn't.

According to the JSP specification your tag/expression combination is illegal syntax.

The weblogic jsp compiler throws an error. The Tomcat compiler handles this case I think.

Referring to the JSP spec section: Quoting and Escape Conventions

- JSP1.2: Section 2.6

- JSP2.0: Section 1.6

Workarounds:

- As you found, splitting the expression

- Use single quotes and double quotes.

<blah:simple selectid='<%=((NameBean)request.getAttribute("NameBean")).getFname()%>'/>

- escape the double quotes?

<blah:simple selectid="<%=((NameBean)request.getAttribute(\"NameBean\")).getFname()%>"/>

evnafetsa at 2007-7-29 16:27:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

That makes sense and fixed the problem. Thanks.

jeff_chisma at 2007-7-29 16:27:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...