I tried to pass UTF-8 String as f:viewParam
value but value shown as garbage string, i added EncodingFilter in web.xml
for setting UTF-8 to request and response as below
HttpServletResponse response = (HttpServletResponse) servletResponse;
HttpServletRequest request = (HttpServletRequest) servletRequest;
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
and i defined facelet page in this style, but problem not resolved
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<f:metadata>
<f:viewParam name="q" value="#{searchBean.query}"/>
</f:metadata>
.....
</html>
I test this with Myfaces 2.0.5 and Mojarra 2.0.5
Apparently you're using a server configuration which interprets GET query strings using a different character encoding by default. For example Tomcat interprets them as ISO-8859-1 by default. You need to open Tomcat's /conf/server.xml
and add URIEncoding
attribute to the <Connector>
element with a value of UTF-8
.
<Connector ... URIEncoding="UTF-8">
That filter is by the way totally unnecessary. Remove it. JSF 2.x on Facelets defaults to UTF-8 at all levels already. Besides, the HttpServletRequest#setCharacterEncoding()
doesn't affect GET requests, it affects POST requests only.