Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - Quotes and EL

 
Thread Tools Search this Thread
Old 11-05-2009, 01:44 PM   #1
Default Quotes and EL


In my Tomcat 6.0.20 container, I have a form value that works great
except if the user enters quotes in the form input. Anything in quotes
wont show up.
For example if they enter: Here is the "info"
The form value would only show: Here is the

Input example that wont work with quotes:
<input type="text" name="city" value="${dataBean.city}" />


If I use tick instead of quotes it works and shows anything in quotes:
<input type="text" name="city" value='${dataBean.city}' />


Please advise why this is happening and if there is an alternate
solution to this issue?


francan
  Reply With Quote
Old 11-05-2009, 02:09 PM   #2
Tim Slattery
 
Posts: n/a
Default Re: Quotes and EL
francan <> wrote:

>In my Tomcat 6.0.20 container, I have a form value that works great
>except if the user enters quotes in the form input. Anything in quotes
>wont show up.
>For example if they enter: Here is the "info"
>The form value would only show: Here is the


>Input example that wont work with quotes:
><input type="text" name="city" value="${dataBean.city}" />


>If I use tick instead of quotes it works and shows anything in quotes:
><input type="text" name="city" value='${dataBean.city}' />


>Please advise why this is happening and if there is an alternate
>solution to this issue?


It's happening because the first quote in the dataBean.city value
terminates the field. For example, if dataBean.city contains

abc"def"gh

Then the line above will result in this HTML:

<input type="text" name="city" value="abc"def"gh" />

So the browser sees that value is abc, then there's some extraneous
garbage, which it ignores.

I haven't been able to find a way to escape quote marks within a field
like this, so I think the only way out for you is to (for example) use
double quotes in your HTML, as you're doing, then have your dataBean
change all double quotes in the value of "city" to single quote marks.
That would avoid conflicts in your HTML, though it would show your
user something that's not exactly what they entered sometimes.

--
Tim Slattery

http://members.cox.net/slatteryt


Tim Slattery
  Reply With Quote
Old 11-06-2009, 03:06 AM   #3
Owen Jacobson
 
Posts: n/a
Default Re: Quotes and EL
On 2009-11-05 09:09:00 -0500, Tim Slattery <> said:

> francan <> wrote:
>
>> In my Tomcat 6.0.20 container, I have a form value that works great
>> except if the user enters quotes in the form input. Anything in quotes
>> wont show up.
>> For example if they enter: Here is the "info"
>> The form value would only show: Here is the

>
>> Input example that wont work with quotes:
>> <input type="text" name="city" value="${dataBean.city}" />

>
>> If I use tick instead of quotes it works and shows anything in quotes:
>> <input type="text" name="city" value='${dataBean.city}' />

>
>> Please advise why this is happening and if there is an alternate
>> solution to this issue?

>
> It's happening because the first quote in the dataBean.city value
> terminates the field. For example, if dataBean.city contains
>
> abc"def"gh
>
> Then the line above will result in this HTML:
>
> <input type="text" name="city" value="abc"def"gh" />
>
> So the browser sees that value is abc, then there's some extraneous
> garbage, which it ignores.
>
> I haven't been able to find a way to escape quote marks within a field
> like this, so I think the only way out for you is to (for example) use
> double quotes in your HTML, as you're doing, then have your dataBean
> change all double quotes in the value of "city" to single quote marks.
> That would avoid conflicts in your HTML, though it would show your
> user something that's not exactly what they entered sometimes.


<cut value="${dataBean.city}" escapeXml="true" /> is your friend here.

There's no built-in way to do it in-line in an EL expression, but you
could expose the same kind of escaping as an EL function in a custom
taglib, at which point you'd also be able to write
${mytags:escape(dataBean.city)} or what have you.

-o



Owen Jacobson
  Reply With Quote
Old 11-10-2009, 06:30 PM   #4
Jean-Baptiste Nizet
 
Posts: n/a
Default Re: Quotes and EL
Owen Jacobson a écrit :
> On 2009-11-05 09:09:00 -0500, Tim Slattery <> said:
>
> <cut value="${dataBean.city}" escapeXml="true" /> is your friend here.
>
> There's no built-in way to do it in-line in an EL expression, but you
> could expose the same kind of escaping as an EL function in a custom
> taglib, at which point you'd also be able to write
> ${mytags:escape(dataBean.city)} or what have you.
>


There is one such standard function :
${fn:escapeXml($dataBean.city)}

see
http://java.sun.com/products/jsp/jst...apeXml.fn.html

JB.


Jean-Baptiste Nizet
  Reply With Quote
Old 11-10-2009, 11:31 PM   #5
Owen Jacobson
 
Posts: n/a
Default Re: Quotes and EL
On 2009-11-10 13:30:52 -0500, Jean-Baptiste Nizet
<> said:

> Owen Jacobson a écrit :
>> On 2009-11-05 09:09:00 -0500, Tim Slattery <> said:
>>
>> <cut value="${dataBean.city}" escapeXml="true" /> is your friend here.
>>
>> There's no built-in way to do it in-line in an EL expression, but you
>> could expose the same kind of escaping as an EL function in a custom
>> taglib, at which point you'd also be able to write
>> ${mytags:escape(dataBean.city)} or what have you.
>>

>
> There is one such standard function :
> ${fn:escapeXml($dataBean.city)}
>
> see http://java.sun.com/products/jsp/jst...apeXml.fn.html
>
> JB.


Well, now, that's handy. Thanks!

-o



Owen Jacobson
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
BEST Auto Insurance quotes for YOUR state. ireneaveline Wireless Networking 0 09-07-2007 04:06 PM
Good quotes: From Celebrities x@y Computer Support 2 04-03-2007 06:21 AM
PHP double quotes inside double quotes MSB Computer Support 11 10-21-2006 02:09 PM
Quicken quotes Mike X Computer Support 4 05-03-2004 01:09 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46