You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Manfred Geiler <ma...@gmail.com> on 2006/04/04 13:04:11 UTC

Re: ResponseWriter Question

The idea is to render the text in HTML as the user would expect even
if he is no HTML expert. Therefore we address the special HTML
whitespace handling here:
 * successive spaces are rendered as &nbsp;
 * line breaks are rendered as <br/>

This is also the difference between write and writeText as I understand it.

Manfred




On 3/20/06, Jacob Hookom <ja...@hookom.net> wrote:
> I noticed in the ResponseWriter:
>
> public void writeText(char cbuf[], int off, int len)
>         throws IOException
>     {
>         if(cbuf == null)
>             throw new NullPointerException("cbuf name must not be null");
>         if(cbuf.length < off + len)
>             throw new IndexOutOfBoundsException((off + len) + " >
> " + cbuf.length);
>         closeStartTagIfNecessary();
>         if(isScriptOrStyle())
>         {
>             String strValue = new String(cbuf, off, len);
>             _writer.write(UnicodeEncoder.encode(strValue, false, false));
>         } else
>         if(isTextarea())
>         {
>             String strValue = new String(cbuf, off, len);
>             _writer.write(HTMLEncoder.encode(strValue, false, false));
>         } else
>         {
>             String strValue = new String(cbuf, off, len);
>             _writer.write(HTMLEncoder.encode(strValue, true, true));
>         }
>     }
>
> In the last case:
>
> HTMLEncoder.encode(strValue, true, true)
>
> Why would you want to tell the HTMLEncoder to write out a line break in
> this case and this case only?
>
> Adam and I are trying to get Facelets to go pure ResponseWriter for all
> encode events, but this little quirk causes pages to render with lots of
> breaks in MyFaces (this doesn't happen in the RI).
>
> --
> Jacob Hookom  -  Minneapolis
> ----------------------------
> JSF-EG, JSF-RI, EL, Facelets
>
>

Re: ResponseWriter Question

Posted by Adam Winer <aw...@gmail.com>.
The intention of writeText() is to escape characters for HTML.
The spec is a rather lax in describing exactly what this means!

That said, I'm uncomfortable with the approach taken here.
I know it solves a common category of problems, but in a way
that's likely to cause a smaller but difficult-to-diagnose and
hard-to-workaround problems (like the ones we're seeing with
Facelets now).  It also adds a weird incompatibility when people
move between the RI and MyFaces (behavioral differences like
this are a bad thing).

I wouldn't say that what MyFaces is doing is wrong - but I wouldn't
say it's right either. ;)

-- Adam




On 4/4/06, Manfred Geiler <ma...@gmail.com> wrote:
> The idea is to render the text in HTML as the user would expect even
> if he is no HTML expert. Therefore we address the special HTML
> whitespace handling here:
>  * successive spaces are rendered as &nbsp;
>  * line breaks are rendered as <br/>
>
> This is also the difference between write and writeText as I understand it.
>
> Manfred
>
>
>
>
> On 3/20/06, Jacob Hookom <ja...@hookom.net> wrote:
> > I noticed in the ResponseWriter:
> >
> > public void writeText(char cbuf[], int off, int len)
> >         throws IOException
> >     {
> >         if(cbuf == null)
> >             throw new NullPointerException("cbuf name must not be null");
> >         if(cbuf.length < off + len)
> >             throw new IndexOutOfBoundsException((off + len) + " >
> > " + cbuf.length);
> >         closeStartTagIfNecessary();
> >         if(isScriptOrStyle())
> >         {
> >             String strValue = new String(cbuf, off, len);
> >             _writer.write(UnicodeEncoder.encode(strValue, false, false));
> >         } else
> >         if(isTextarea())
> >         {
> >             String strValue = new String(cbuf, off, len);
> >             _writer.write(HTMLEncoder.encode(strValue, false, false));
> >         } else
> >         {
> >             String strValue = new String(cbuf, off, len);
> >             _writer.write(HTMLEncoder.encode(strValue, true, true));
> >         }
> >     }
> >
> > In the last case:
> >
> > HTMLEncoder.encode(strValue, true, true)
> >
> > Why would you want to tell the HTMLEncoder to write out a line break in
> > this case and this case only?
> >
> > Adam and I are trying to get Facelets to go pure ResponseWriter for all
> > encode events, but this little quirk causes pages to render with lots of
> > breaks in MyFaces (this doesn't happen in the RI).
> >
> > --
> > Jacob Hookom  -  Minneapolis
> > ----------------------------
> > JSF-EG, JSF-RI, EL, Facelets
> >
> >
>