You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Arnaud Jeansen <ar...@edifixio.fr> on 2006/01/18 19:04:00 UTC

RE : unencode &# encodings in javascript

Hi,
 
We had the same problem here, when trying to inject special french
characters in a javascript string (simple client validation on a JSF
component). The javascript string received a unicode translated value
(&#233; in our case), breaking the javascript code.
onfocus="checkDefaultValue(this, '#{labels.menu_incident_number}');"

The reason why this breaks is hard to identify, I tested as well with simple
alerts on a plain HTML page and couldn't see this happen.
 
We found a simple solution that works for us, replacing the simple quotes by
escaped double quotes:
onfocus="checkDefaultValue(this, \"#{labels.menu_incident_number}\");"

Surprisingly enough, the &#xxx; characters work fine when surrounded this
way. I can offer no real explanation about this behavior, but I hope this
might solve your problems.
 
Bye,
Arnaud
 

-----Message d'origine-----
De : Enrique Medina [mailto:e.medina.m@gmail.com] 
Envoyé : mercredi 18 janvier 2006 18:21
À : MyFaces Discussion; werpu@gmx.at
Objet : Re: unencode &# encodings in javascript


Hi,

I face the same situation. The problem is that MyFaces encodes all HTML and
all messages from the ResourceBundle, so the Javascript alert shows those
annoying &nnn; characters....


2006/1/18, Werner Punz <we...@gmx.at>: 

I do not know if there is a function but the \unnn notation works 
definitely with alerts:

http://www.zid.tugraz.at/peter/javascript/unicode.html

I am not sure but the #nnn notation might be unicode numbers so they might 
be the same numbers as in the \unnn notation


Mario Ivankovits schrieb:
> Hi!
>
> We merged our JSP project with JSF so we can slowly migrate to JSF at all.
> This has been done by heavily using the verbatim tag - and even if its 
> butt ugly ;-) it works.
>
> Though, there is still one problem left.
> Now that the whole page renderes through the HtmlResponseWriter all the
> "umlauts" are converted to the &#nnn; form. 
>
> Normally this is not a problem as the browser successfully handles it -
> normally - but not when using the javascript function alert() to print
> such a string.
>
> What I need now is a javascript function to unencode this string - is 
> there already something in myfaces of do one know a library for this.
> I can create one myself, but I thought I'll ask before.
>
>
> Thanks!
> Mario
>
>