Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set charset in a primefaces webapp? [duplicate]

Let me share my unique disapointment with the primefaces 3.1, until now... I'm using a phew components in a RichFaces app, everthing fine when i realized an issue, some characters in my native language are displayed wrong, even UTF-8 charset being declared in all places i know it's required.

The problem occur when is entered some special character like "São Paulo" in a and submited the page. The data after submit is redisplays as "São Paulo"

I already tried the folowing work-around:

1)Eclipse IDE : text file enconding option

2)jsf files:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 

3)JBOSS server.xml:

<Connector protocol="HTTP/1.1" URIEncoding="UTF-8" port="${jboss.web.http.port}" address="0.0.0.0" 
         redirectPort="${jboss.web.https.port}" />

4)web.xml:

<?xml version="1.0" encoding="UTF-8"?>

5)jsf file:

<h:form acceptcharset="UTF-8" enctype="application/form-data">

6)upgrade the primefaces version to 3.2

Thanks for any help! ;-)

like image 979
Guilherme Avatar asked Mar 14 '12 20:03

Guilherme


2 Answers

i've been forced to create a filter who sets the charset for every request...

public class CharacterEncodingFilter implements Filter {

    @Override
    public void destroy() {
        // TODO Auto-generated method stub
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");
        chain.doFilter(request, response);
    }

    @Override
    public void init(FilterConfig arg0) throws ServletException {
        // TODO Auto-generated method stub
    }

}

that's solve my issue

like image 193
Guilherme Avatar answered Nov 07 '22 13:11

Guilherme


I just uncomment that portion in conf/web.xml (Tomcat server web.xml) that filter all request and convert into UTF-8.

 <!-- A filter that sets character encoding that is used to decode URIs-->
 <!-- parameters in a POST request -->
 <filter>
        <filter-name>setCharacterEncodingFilter</filter-name>
        <filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
 </filter>

  <!-- The mapping for the Set Character Encoding Filter -->
  <filter-mapping>
        <filter-name>setCharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
  </filter-mapping>
like image 26
Divyesh Kanzariya Avatar answered Nov 07 '22 13:11

Divyesh Kanzariya