• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1182
  • Last Modified:

need to escape names with apostrophe

I have a jap which has an hyperlink and upon clicking that hyperlink calls a javascript method.
There are 5  parameters inside javascript function. and one of the parameters is a string lastname

In scenarios where  a lastname has an apostrophe in them example L'Esperance while calling a javascript function ,this apostrophe acts like an end of function and doesnt call the javascript function and displays javascript "error on page"

I need to escape names with apostrophe  in them.

Here is my chunck of code where its calling javascript function

<html:link href="javascript:somefunction('${someVO.context}', '${rsoeVO.displayType}', 'true', '${guestInformationVO.lastName}', '${rsomeVO.confirmationNumber}');">
      click here      </html:link>

${guestInformationDisplayVO.lastName} gives L'Esperance

I need to remove the apostrophe from this:  ${guestInformationDisplayVO.lastName}

I tried to use javascript:escape(${guestInformationDisplayVO.lastName}) ..but didnt work

anyhelp would be great


0
pacchureddy
Asked:
pacchureddy
3 Solutions
 
suprapto45Commented:
Hi,

Can't you escape it from your Java app when you are storing the value into guestInformationVO?

David
0
 
suprapto45Commented:
I mean from your Java codes ;)

David
0
 
pacchureddyAuthor Commented:

I dont want to remove the apostrophe completly from lastnames . Only when calling this javascript function  I want to escape the apostrophe .so the call to the javascript function is made.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
actonwangCommented:
hi,pacchureddy,

        You can simply  use jstl1.1 bulit-in function fn:replace as the following:
         
        ${fn:replace(guestInformationVO.lastName,"'"," ")}

        L'Espe will become   L Espe.

        You can also provide different substition for  apostrophe.      

Enjoy      

Acton
0
 
actonwangCommented:
if you want to avoid jstl (most of people will like it though :), then you have to create your own version of el function as fn:replace then use it in your el expression.

Acton
0
 
TimYatesCommented:
You can use:

    java.net.URLEncoder.encode( guestInformationVO.lastName, "UTF8" )

then use:

   unescape( param )

in the javascript method

To use it in a tag, you can use the Jakarta string taglib:  http://jakarta.apache.org/taglibs/doc/string-doc/string-1.1.0/index.html#encodeUrl

Tim
0
 
astrohelpCommented:
I am just curious why you are using their last name instead of some type of ID, I realize this is not a solution to your problem, but as I said, just curious.
0
 
suprapto45Commented:
Nope,

>>"I dont want to remove the apostrophe completly from lastnames "
You can embed the "\" escape character in your Java codes. So you got to check whether the last name contains any apostrophe. If so, you have to add the "\". Hence L'Espe becomes L\'Espe

Thanks
David
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now