You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Randahl Fink Isaksen <ra...@rockit.dk> on 2006/10/26 18:58:11 UTC

Why does MyFaces escape national characters?

According to the JSF1.1 spec section 6.4 the ResponseWriter 
implementation should be "performing
appropriate character encoding and escaping", but I think MyFaces seems 
to have taken this a bit too far. Not only does it escape characters 
which has a special meaning in XML, like the < character, it also 
escapes national characters like the Danish 'ae' character which it 
transforms to its escape equivalent ("&#230;"). This seems to me to be 
completely unnecessary when outputting unicode formatted XML, since 
unicode supports 'ae' and since 'ae' does not have a special meaning in XML.

This turns out to be a problem in my application of MyFaces because I 
would like to output something like this:

<div id="Vandm&#230;rke">

where the "&#230;" should in fact have been the danish letter 'ae'.

Can anyone elaborate on why MyFaces would do this and/or if this 
behavior can be configured to work otherwise?

Thanks

Randahl


Re: Why does MyFaces escape national characters?

Posted by Randahl Fink Isaksen <ra...@rockit.dk>.
I did some more diggging at it is indeed MyFaces which provides the 
ResponseWriter. It is actually an instance of

org.apache.myfaces.shared_impl.renderkit.html.HtmlResponseWriterImpl

The reason why it converts special characters in my output xml is that 
MyFaces never realises that I am outputting UTF-8. The code in this 
class directly states that if I am outputting UTF-8 it will not escape 
special characters since any character is supported in UTF-8, but if it 
cannot see that I am outputting UTF-8 it will do the escaping.

So how can I tell MyFaces that I am always using UTF-8?

Randahl



Randahl Fink Isaksen wrote:
> But is MyFaces not the system that provides the ResponseWriter? Or is 
> it facelets?
>
> Randahl
>
>
> tetsuo wrote:
>> I think Facelets escapes special characters by default, at least when
>> they are in a template. But I don't know if it also affects the
>> programmatic API...
>>
>>
>>
>>
>> On 10/26/06, Randahl Fink Isaksen <ra...@rockit.dk> wrote:
>>> Nope - I am outputting a div from my own custom component like this:
>>>
>>>         writer.startElement("div", this);
>>>         writer.writeAttribute("id", theId, null);
>>>
>>> where the variable "theId" contains this string "Vandmaerke" in which
>>> 'ae' is a single special Danish character.
>>>
>>> Thus I can only suspect MyFaces to be responsible for the conversion. I
>>> am using MyFaces with facelets, but I presume the ResponseWriter is 
>>> part
>>> of MyFaces and not Facelets and thus I posted the question here 
>>> (correct
>>> me if I am wrong).
>>>
>>> Randahl
>>>
>>>
>>>
>>>
>>> Jeff Bischoff wrote:
>>> > Randahl,
>>> >
>>> > Are you using a t:div?
>>> >
>>> > Randahl Fink Isaksen wrote:
>>> >> According to the JSF1.1 spec section 6.4 the ResponseWriter
>>> >> implementation should be "performing
>>> >> appropriate character encoding and escaping", but I think MyFaces
>>> >> seems to have taken this a bit too far. Not only does it escape
>>> >> characters which has a special meaning in XML, like the < character,
>>> >> it also escapes national characters like the Danish 'ae' character
>>> >> which it transforms to its escape equivalent ("&#230;"). This seems
>>> >> to me to be completely unnecessary when outputting unicode formatted
>>> >> XML, since unicode supports 'ae' and since 'ae' does not have a
>>> >> special meaning in XML.
>>> >>
>>> >> This turns out to be a problem in my application of MyFaces 
>>> because I
>>> >> would like to output something like this:
>>> >>
>>> >> <div id="Vandm&#230;rke">
>>> >>
>>> >> where the "&#230;" should in fact have been the danish letter 'ae'.
>>> >>
>>> >> Can anyone elaborate on why MyFaces would do this and/or if this
>>> >> behavior can be configured to work otherwise?
>>> >>
>>> >> Thanks
>>> >>
>>> >> Randahl
>>> >>
>>> >>
>>> >>
>>> >>
>>> >
>>> >
>>> >
>>> >
>>>
>>>
>>
>>
>
>
>


Re: Why does MyFaces escape national characters?

Posted by Randahl Fink Isaksen <ra...@rockit.dk>.
But is MyFaces not the system that provides the ResponseWriter? Or is it 
facelets?

Randahl


tetsuo wrote:
> I think Facelets escapes special characters by default, at least when
> they are in a template. But I don't know if it also affects the
> programmatic API...
>
>
>
>
> On 10/26/06, Randahl Fink Isaksen <ra...@rockit.dk> wrote:
>> Nope - I am outputting a div from my own custom component like this:
>>
>>         writer.startElement("div", this);
>>         writer.writeAttribute("id", theId, null);
>>
>> where the variable "theId" contains this string "Vandmaerke" in which
>> 'ae' is a single special Danish character.
>>
>> Thus I can only suspect MyFaces to be responsible for the conversion. I
>> am using MyFaces with facelets, but I presume the ResponseWriter is part
>> of MyFaces and not Facelets and thus I posted the question here (correct
>> me if I am wrong).
>>
>> Randahl
>>
>>
>>
>>
>> Jeff Bischoff wrote:
>> > Randahl,
>> >
>> > Are you using a t:div?
>> >
>> > Randahl Fink Isaksen wrote:
>> >> According to the JSF1.1 spec section 6.4 the ResponseWriter
>> >> implementation should be "performing
>> >> appropriate character encoding and escaping", but I think MyFaces
>> >> seems to have taken this a bit too far. Not only does it escape
>> >> characters which has a special meaning in XML, like the < character,
>> >> it also escapes national characters like the Danish 'ae' character
>> >> which it transforms to its escape equivalent ("&#230;"). This seems
>> >> to me to be completely unnecessary when outputting unicode formatted
>> >> XML, since unicode supports 'ae' and since 'ae' does not have a
>> >> special meaning in XML.
>> >>
>> >> This turns out to be a problem in my application of MyFaces because I
>> >> would like to output something like this:
>> >>
>> >> <div id="Vandm&#230;rke">
>> >>
>> >> where the "&#230;" should in fact have been the danish letter 'ae'.
>> >>
>> >> Can anyone elaborate on why MyFaces would do this and/or if this
>> >> behavior can be configured to work otherwise?
>> >>
>> >> Thanks
>> >>
>> >> Randahl
>> >>
>> >>
>> >>
>> >>
>> >
>> >
>> >
>> >
>>
>>
>
>


Re: Why does MyFaces escape national characters?

Posted by tetsuo <ro...@gmail.com>.
I think Facelets escapes special characters by default, at least when
they are in a template. But I don't know if it also affects the
programmatic API...




On 10/26/06, Randahl Fink Isaksen <ra...@rockit.dk> wrote:
> Nope - I am outputting a div from my own custom component like this:
>
>         writer.startElement("div", this);
>         writer.writeAttribute("id", theId, null);
>
> where the variable "theId" contains this string "Vandmaerke" in which
> 'ae' is a single special Danish character.
>
> Thus I can only suspect MyFaces to be responsible for the conversion. I
> am using MyFaces with facelets, but I presume the ResponseWriter is part
> of MyFaces and not Facelets and thus I posted the question here (correct
> me if I am wrong).
>
> Randahl
>
>
>
>
> Jeff Bischoff wrote:
> > Randahl,
> >
> > Are you using a t:div?
> >
> > Randahl Fink Isaksen wrote:
> >> According to the JSF1.1 spec section 6.4 the ResponseWriter
> >> implementation should be "performing
> >> appropriate character encoding and escaping", but I think MyFaces
> >> seems to have taken this a bit too far. Not only does it escape
> >> characters which has a special meaning in XML, like the < character,
> >> it also escapes national characters like the Danish 'ae' character
> >> which it transforms to its escape equivalent ("&#230;"). This seems
> >> to me to be completely unnecessary when outputting unicode formatted
> >> XML, since unicode supports 'ae' and since 'ae' does not have a
> >> special meaning in XML.
> >>
> >> This turns out to be a problem in my application of MyFaces because I
> >> would like to output something like this:
> >>
> >> <div id="Vandm&#230;rke">
> >>
> >> where the "&#230;" should in fact have been the danish letter 'ae'.
> >>
> >> Can anyone elaborate on why MyFaces would do this and/or if this
> >> behavior can be configured to work otherwise?
> >>
> >> Thanks
> >>
> >> Randahl
> >>
> >>
> >>
> >>
> >
> >
> >
> >
>
>

Re: Why does MyFaces escape national characters?

Posted by Randahl Fink Isaksen <ra...@rockit.dk>.
Nope - I am outputting a div from my own custom component like this:

        writer.startElement("div", this);
        writer.writeAttribute("id", theId, null);

where the variable "theId" contains this string "Vandmaerke" in which 
'ae' is a single special Danish character.

Thus I can only suspect MyFaces to be responsible for the conversion. I 
am using MyFaces with facelets, but I presume the ResponseWriter is part 
of MyFaces and not Facelets and thus I posted the question here (correct 
me if I am wrong).

Randahl




Jeff Bischoff wrote:
> Randahl,
>
> Are you using a t:div?
>
> Randahl Fink Isaksen wrote:
>> According to the JSF1.1 spec section 6.4 the ResponseWriter 
>> implementation should be "performing
>> appropriate character encoding and escaping", but I think MyFaces 
>> seems to have taken this a bit too far. Not only does it escape 
>> characters which has a special meaning in XML, like the < character, 
>> it also escapes national characters like the Danish 'ae' character 
>> which it transforms to its escape equivalent ("&#230;"). This seems 
>> to me to be completely unnecessary when outputting unicode formatted 
>> XML, since unicode supports 'ae' and since 'ae' does not have a 
>> special meaning in XML.
>>
>> This turns out to be a problem in my application of MyFaces because I 
>> would like to output something like this:
>>
>> <div id="Vandm&#230;rke">
>>
>> where the "&#230;" should in fact have been the danish letter 'ae'.
>>
>> Can anyone elaborate on why MyFaces would do this and/or if this 
>> behavior can be configured to work otherwise?
>>
>> Thanks
>>
>> Randahl
>>
>>
>>
>>
>
>
>
>


Re: Why does MyFaces escape national characters?

Posted by Jeff Bischoff <jb...@klkurz.com>.
Randahl,

Are you using a t:div?

Randahl Fink Isaksen wrote:
> According to the JSF1.1 spec section 6.4 the ResponseWriter 
> implementation should be "performing
> appropriate character encoding and escaping", but I think MyFaces seems 
> to have taken this a bit too far. Not only does it escape characters 
> which has a special meaning in XML, like the < character, it also 
> escapes national characters like the Danish 'ae' character which it 
> transforms to its escape equivalent ("&#230;"). This seems to me to be 
> completely unnecessary when outputting unicode formatted XML, since 
> unicode supports 'ae' and since 'ae' does not have a special meaning in 
> XML.
> 
> This turns out to be a problem in my application of MyFaces because I 
> would like to output something like this:
> 
> <div id="Vandm&#230;rke">
> 
> where the "&#230;" should in fact have been the danish letter 'ae'.
> 
> Can anyone elaborate on why MyFaces would do this and/or if this 
> behavior can be configured to work otherwise?
> 
> Thanks
> 
> Randahl
> 
> 
> 
> 



Re: Why does MyFaces escape national characters?

Posted by Randahl Fink Isaksen <ra...@rockit.dk>.
I would like to ask again: Can anyone tell me why MyFaces converts 
unicode characters to their &#xyz; equivalents when we invoke

facesContext.getResponseWriter().writeAttribute("id", myName);

Here myName contains a string which contains a unicode character 'ae' 
that is the equivalent of &#230;.

I am outputting UTF-8 XML in which all unicode characters are acceptable 
except XML special characters like < and &, so I do not understand why 
'ae' is converted to &#230; when 'ae' is itself legal XML.

Randahl






Randahl Fink Isaksen wrote:
> According to the JSF1.1 spec section 6.4 the ResponseWriter 
> implementation should be "performing
> appropriate character encoding and escaping", but I think MyFaces 
> seems to have taken this a bit too far. Not only does it escape 
> characters which has a special meaning in XML, like the < character, 
> it also escapes national characters like the Danish 'ae' character 
> which it transforms to its escape equivalent ("&#230;"). This seems to 
> me to be completely unnecessary when outputting unicode formatted XML, 
> since unicode supports 'ae' and since 'ae' does not have a special 
> meaning in XML.
>
> This turns out to be a problem in my application of MyFaces because I 
> would like to output something like this:
>
> <div id="Vandm&#230;rke">
>
> where the "&#230;" should in fact have been the danish letter 'ae'.
>
> Can anyone elaborate on why MyFaces would do this and/or if this 
> behavior can be configured to work otherwise?
>
> Thanks
>
> Randahl
>
>
>