1

I have a problem encoding the outcome of an action method into UTF-8 using.

Glassfish 3.1.2 is set to UTF-8: <parameter-encoding default-charset="UTF-8"/> and entering following UTF-8 encoded url into the browser results in correct decoded view-parameter retrieval in the bean/converter.

/sites/foo.xhtml?paramKey=Getr%C3%A4nke -> /sites/foo.xhtml?paramKey=Getränke

Getränke is retrieved correctly in the backing bean and my converters can retrieve the correct objects.

Problem:

Within a bean method that is invoked by a command component view parameters are appended to the targeted view-id that will be returned.

public String action()
{
    return "/sites/foo.xhtml?paramKey=Getränke&faces-redirect=true";
}

Will result in an ISO-8859-1 encoded url instead of UTF-8 encoded after the redirect:

/sites/foo.xhtml?paramKey=Getr%E4nke

Did I missed to define UTF-8 somewhere?

Or do I manually have to encode the outcome to UTF-8 myself, which works. Strangely the basic links like h:link work fine.

System:

Glassfish 3.1.2 Mojarra 3.1.23 Primefaces 3.5f Omnifaces: 1.6 snapshot

Note: also removed PrettyURL or //Rewrite for testing to make sure this cannot be the reason.

Note: for testing also added following to a filter:

if (request.getCharacterEncoding() == null)
    response.setCharacterEncoding("UTF-8");
4

1 回答 1

1

一年多以前,我已经准确地报告了这个问题:issue 2440。不幸的是,他们只为 2.2 而不是 2.1 修复了它,因为它需要更改 JSF 规范。由于您已经在使用 OmniFaces,因此您也可以使用它Faces#redirect()。它使用明确的 UTF-8 对参数进行 URL 编码。

public void action() throws IOException {
    Faces.redirect("sites/foo.xhtml?paramKey=%s", "Getränke");
}
于 2013-08-29T23:38:37.900 回答