[prev in list] [next in list] [prev in thread] [next in thread] 

List:       taglibs-user
Subject:    Re: passing references to tags using XML syntax
From:       August Gresens <august () blackhammer ! com>
Date:       2002-02-15 16:01:09
[Download RAW message or body]

Thanks. I must say, however, I was afraid this is what the answer would 
be. This makes for very messy JSP code that is difficult to read.

Perhaps someone has written a taglib as a work-around for this?

<html:a href="%= ref %">foo</a>

August

On Thursday, February 14, 2002, at 03:05 PM, Shawn Bayern wrote:

> The "%= ... %" syntax is intended only for custom actions (and those
> standard-action attributes that support it).  Inserting dynamic text 
> into
> an HTML tag's attribute is just like inserting dynamic text into 
> arbitrary
> static, template text.  The problem is that under the XML syntax, you
> can't simply include one tag within another; the tags are "coordinate" 
> in
> the XML syntax, unlike in the JSP syntax where one tag is recognized by
> the language (JSP) and the other isn't.
>
> To get around the problem in the XML syntax, you need to treat the HTML
> tag explicitly as template text.  You can, for instance, use <jsp:text>
> with the appropriate entity references, as follows:
>
> <jsp:text>
>  &lt;a 
> href="</jsp:text><jsp:expression>myURL</jsp:expression><jsp:text>"&gt;
> </jsp:text>
>
> (Note how I've been careful about whitespace.)
>
> Alternatively, if "escaping" characters gets cumbersome, you can always
> use an XML CDATA block.
>
> --
> Shawn Bayern
> Author, "JSP Standard Tag Library"  http://www.jstlbook.com
> (coming this spring from Manning Publications)
>
> On Thu, 14 Feb 2002, August Gresens wrote:
>
>> The solution from the spec worked for the use with the input taglib.
>>
>> I'm now having a problem with standard HTML tags, when I want to 
>> include
>> values I have declared elsewhere in the code.
>>
>> For example
>>
>> <jsp:declaration>
>>
>> String myURL = "http://www.foo.com" ;
>>
>> </jsp:declaration>
>>
>> Later in the page, I want to reference this value in constructing a 
>> URL:
>>
>> <a href="%= myURL%">click here</a>
>>
>> in the output, the substitution is not made. The output is printed
>> exactly as it is in the JSP page.
>>
>> I am doing something wrong here?
>>
>> Thanks,
>>
>> August
>>
>>
>> On Wednesday, February 13, 2002, at 03:25 PM, Shawn Bayern wrote:
>>
>>> On Wed, 13 Feb 2002, August Gresens wrote:
>>>
>>>> options="<%= o %>" />
>>>>
>>>> With XML syntax, this won't work because the "<" and ">" characters
>>>> are illegal in XML with attributes, and JSP chokes while attempting 
>>>> to
>>>> parse it.
>>>>
>>>> Does anyone know how to do this? Is there a new syntax for the XML
>>>> syntax to indicate to JSP that a reference instead of a value is 
>>>> being
>>>> passed (like XSLT's "$" operator).
>>>
>>> Yes:  "%= rtexprvalye %".
>>>
>>> Section 5.3.11 of the JSP specification provides the full info:
>>>
>>>   Request-time attribute expressions are of the form <%= 
>>> expression %>.
>>>   Although this syntax is consistent with the syntax used elsewhere 
>>> in a
>>>   JSP page, it is not a legal XML syntax. The XML mapping for these
>>>   expressions is into values of the form %= expression %, where the 
>>> JSP
>>>   specification quoting convention has been converted to the XML 
>>> quoting
>>>   convention.
>>>
>>> Also, it's worthwhile pointing out that since JSTL's (and JSP 1.3's
>>> likely) expression language will not rely on the rtexprvalue syntax, 
>>> it
>>> won't need this sort of escaping.  In other words, your <c:forEach> 
>>> tag
>>> should work similarly under the familiar and XML views of the page.
>>>
>>> --
>>> Shawn Bayern
>>> Author, "JSP Standard Tag Library"  http://www.jstlbook.com
>>> (coming soon from Manning Publications)
>>>
>>>
>>> --
>>> To unsubscribe, e-mail:   <mailto:taglibs-user-
>>> unsubscribe@jakarta.apache.org>
>>> For additional commands, e-mail: <mailto:taglibs-user-
>>> help@jakarta.apache.org>
>>>
>>
>>
>> --
>> To unsubscribe, e-mail:   <mailto:taglibs-user-
>> unsubscribe@jakarta.apache.org>
>> For additional commands, e-mail: <mailto:taglibs-user-
>> help@jakarta.apache.org>
>>
>
>
> --
> To unsubscribe, e-mail:   <mailto:taglibs-user-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:taglibs-user-
> help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <mailto:taglibs-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:taglibs-user-help@jakarta.apache.org>

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic