I have just implemented your workaround and it also works great for me.
But shouldn't it be a more generic and straightforward mechanism to solve this problem? To the best of my knowledge, the problem is with the class HTMLEncoder, and particularly with this method:
public static String encode (String string,
boolean encodeNewline,
boolean encodeSubsequentBlanksToNbsp,
boolean encodeNonLatin)
where this code is executed:
default :
if (((int)c) >= 0x80)
{
//encode all non basic latin characters
app = "&#" + ((int)c) + ";";
}
break;
So my "tildes" in spanish are always encoded too.
2006/1/19, Mario Ivankovits <[EMAIL PROTECTED]>:
Hi!
> 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.
>
Thanks for your tips.
*) \u - you cant convert a &# to \u (even if its the same code what I
don't know now) - however \u will be evaluated at parsing time, so you
cant do something like alert(string.replace("&#", "\u")) nor "\\u"
*) I have absolutely no clue why the \" stuff works, and here I had no
luck with it.
So here is what I do now.
There are only a handful places in our _javascript_ where we alert
something to the user, I'll replace alert( by something like myAlert().
In there, before passing the string to alert() I will convert the string
using the following simple script:
/**
* decodes all &#nnn; in the given text to its corresponding character
*/
function decodeHexEntity(text)
{
var entitySearch = /&#[0-9]+;/g;
var entity;
while (entity = entitySearch.exec(text))
{
var charCode = entity[0].substring(2, entity[0].length -1);
text = text.substring(0, entity.index)
+ String.fromCharCode (charCode)
+ text.substring(entity.index + entity[0].length);
}
return text;
}
Maybe not the most performant solution, but easily done and it wont be
used in time critical _javascript_ code ;-)
So maybe someone else might find it useful too.
Ciao,
Mario

