You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Apache Wiki <wi...@apache.org> on 2007/05/24 06:12:49 UTC

[Tapestry Wiki] Update of "Utf8EncodingInT5" by NickWestgate

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for change notification.

The following page has been changed by NickWestgate:
http://wiki.apache.org/tapestry/Utf8EncodingInT5

The comment on the change is:
How to add UTF-8 encoding/decoding to T5

New page:
= Integrating Spring & T5 =

At the time of writing, T5 (version 5.0.5-SNAPSHOT) doesn't have built-in support for UTF-8 encoding, but this will certainly be included in one of the upcoming releases.

In the meantime, follow the instructions below to use "foreign" characters, i.e. ones outside ISO-8859-1.

== In your AppModule.java file, add the following methods ==


{{{

    public RequestFilter buildUtf8Filter(
        @InjectService("RequestGlobals") final RequestGlobals requestGlobals)
    {
        return new RequestFilter()
        {
            public boolean service(Request request, Response response, RequestHandler handler)
                throws IOException
            {
                requestGlobals.getHTTPServletRequest().setCharacterEncoding("UTF-8");
                return handler.service(request, response);
            }
        };
    }

    public static PageResponseRenderer decoratePageResponseRenderer(
        @InjectService("PageMarkupRenderer") final PageMarkupRenderer markupRenderer,
        @InjectService("MarkupWriterFactory") final MarkupWriterFactory markupWriterFactory,
        final Object delegate)
    {

        return new PageResponseRenderer()
        {
            public void renderPageResponse(Page page, Response response) throws IOException
            {
                MarkupWriter writer = markupWriterFactory.newMarkupWriter();
                markupRenderer.renderPageMarkup(page, writer);
                PrintWriter pw = response.getPrintWriter("text/html; charset=UTF-8");
                writer.toMarkup(pw);
                pw.flush();
            }
        };
    }

}}}

== Now update your contributeRequestHandler() method ==

(Note that in earlier versions this was called contributeRequestFilters.)

{{{

    public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
            @InjectService("TimingFilter") final RequestFilter timingFilter,
            @InjectService("Utf8Filter") final RequestFilter utf8Filter)
    {
        configuration.add("Utf8Filter", utf8Filter); // handle UTF-8
        configuration.add("Timing", timingFilter);
    }

}}}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org