You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Paul DuBois <pa...@snake.net> on 2002/05/23 19:40:13 UTC

[JSTL] Use of quotes inside []

JSTL allows varName[propertyName] syntax.  I'm curious about the quoting
requirements for propertyName.  For example, in the JSTL spec, page 3-20,
there is an example that looks like this:

<c:out value='${user.preferences["shipping"]}'/>

Most examples in the spec use double quotes around attribute values,
but this example switches to single quotes so that the property name
can be double-quoted.

I thought perhaps it was a requirement that the property name be enclosed
in double quotes, but a few tests using single quotes seem to work as well.
Is that officially supported, or did I just get lucky?

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [JSTL] Use of quotes inside []

Posted by Paul DuBois <pa...@snake.net>.
>Hi Paul.  Sorry for my delay in answering questions!  I've been on the
>road.

Yeah, I wondered about that.  Usually JSTL questions on this list get
answered in a matter of minutes. :-)

>
>>  JSTL allows varName[propertyName] syntax.  I'm curious about the quoting
>>  requirements for propertyName.  For example, in the JSTL spec, page 3-20,
>>  there is an example that looks like this:
>>
>>  <c:out value='${user.preferences["shipping"]}'/>
>>
>>  Most examples in the spec use double quotes around attribute values,
>>  but this example switches to single quotes so that the property name
>>  can be double-quoted.
>>
>>  I thought perhaps it was a requirement that the property name be
>>  enclosed in double quotes, but a few tests using single quotes seem to
>>  work as well. Is that officially supported, or did I just get lucky?
>
>Single quotes are a valid quoting syntax in JSTL's expression language; a
>single-quoted sequence of characters is interpreted as a string literal. 
>Thus,
>
>   preferences['shipping']
>
>is okay.  The choice of which quoting mechanism to use is predominantly a
>matter of style and convenience.

Good, thanks.  I prefer to always double-quote attributes for consistency,
so I'll use single quotes around property names.

>
>--
>Shawn Bayern
>"JSP Standard Tag Library"   http://www.jstlbook.com
>(coming in July 2002 from Manning Publications)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [JSTL] Use of quotes inside []

Posted by Shawn Bayern <ba...@essentially.net>.
Hi Paul.  Sorry for my delay in answering questions!  I've been on the
road.

> JSTL allows varName[propertyName] syntax.  I'm curious about the quoting
> requirements for propertyName.  For example, in the JSTL spec, page 3-20,
> there is an example that looks like this:
> 
> <c:out value='${user.preferences["shipping"]}'/>
> 
> Most examples in the spec use double quotes around attribute values,
> but this example switches to single quotes so that the property name
> can be double-quoted.
> 
> I thought perhaps it was a requirement that the property name be
> enclosed in double quotes, but a few tests using single quotes seem to
> work as well. Is that officially supported, or did I just get lucky?

Single quotes are a valid quoting syntax in JSTL's expression language; a
single-quoted sequence of characters is interpreted as a string literal.  
Thus,

  preferences['shipping']

is okay.  The choice of which quoting mechanism to use is predominantly a
matter of style and convenience.

-- 
Shawn Bayern
"JSP Standard Tag Library"   http://www.jstlbook.com
(coming in July 2002 from Manning Publications)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>