I do not know off hand what the relevant JSP spec says about runtime
expressions in tag attributes (maybe Hans can chime in, if he's on this
list), but what you described matches my experience under the web container
provided by Weblogic 6.1.  It should be trivial, especially in the example
you provided, to do the string concat in your scriptlet rather than trying
to pass a value to a custom tag that is half  regular text and half runtime
expression.  One trick we've used is

<my:MyTag name="<%=userName + "_guest" %>"/>

which gets around this seemingly odd limitation of tag attributes.

Don't confuse HTML tags with JSP tags.  JSP tags are run through a
translation phase, where rules like where runtime attributes can be used,
what attributes are required, etc. are enforced.  The output of translation
is Java source code that is compiled.  All HTML tages ultimately just end up
as literals in println() calls in that source code, or the equivalent.  That
is, HTML tags don't have to obey any special rules in the JSP translation
phase, unlike JSP tags, because they are part of what the JSP spec refers to
as template text--that HTML could just as easily be XML or WML or a csv file
or any other kind of text, the JSP container doesn't care.

Thomas Gideon
Sr. Software Developer
B2eMarkets

301.230.2236  Tel.
301.230.2248  Fax.
[EMAIL PROTECTED]
www.B2eMarkets.com



> -----Original Message-----
> From: shanmugampl [mailto:[EMAIL PROTECTED]]
> Sent: Friday, September 27, 2002 8:24 AM
> To: [EMAIL PROTECTED]
> Subject: Issue in giving runtime expression for custom tag attributes
> 
> 
> Hi All,
> 
>         I am developing some custom tags for my application. 
> For one of 
> my tag attributes i have the rtexprvalue set to true. The following 
> scenario does not work
> 
> Usage:
> <%
> String userName = "Shan"
> %>
> <my:MyTag name="<%=userName%>_guest"/>
> 
> When i see the generated code, the value for userName is not 
> replaced, 
> and the whole expression is considered as a String and passed to the 
> method.
> i.e the setName method is called as setName("<%=userName%>_guest");
> 
> but the result i expected was
> setName(userName+"_guest");
> 
> The same thing works fine if i give it as
> 
> <my:MyTag name="<%=userName%>"/>
> 
> and the generated result was setName(userName);
> 
> Is this a bug  or the expected functionality because for 
> other html tags 
> such as input i can specify it as
> 
> <input value="text<%=userName%>"/>
> 
> Thanks
> Shanmugam.PL
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: 
> <mailto:[EMAIL PROTECTED]>
> 

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to