Question

Problems started when I upgraded Mojarra from 2.2.1 to 2.2.3 (JBoss Wildfly Alpha to Beta).

When I try to submit a form (POST) with special characters (polish letters) they aren't properly UTF-8 encoded.

What I have done?

  • Wrote a filter

    @WebFilter(urlPatterns = "/*", initParams = { @WebInitParam(name = "ignore", value = "true" ), @WebInitParam(name = "encoding", value = "UTF-8") })
    public class CharacterEncodingFilter implements Filter {
    
        private String encoding = null;
        private FilterConfig filterConfig;
    
        // Should a character encoding specified by client be ignored
        private boolean ignore = true;
    
        @Override
        public void init(FilterConfig filterConfig) throws ServletException {
            this.filterConfig = filterConfig;
            this.encoding = filterConfig.getInitParameter("encoding");
            String value = filterConfig.getInitParameter("ignore");
    
            this.ignore = ((value == null) || value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"));
        }
    
        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    
            if ((ignore || (request.getCharacterEncoding() == null)) && (encoding != null)) {
                request.setCharacterEncoding(encoding);
                response.setCharacterEncoding(encoding);
            }
    
            chain.doFilter(request, response);
        }
    
        @Override
        public void destroy() {
            this.encoding = null;
            this.filterConfig = null;
        }
    }
    
  • Every XHTML contains a line

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

  • Layout also contains information about encoding

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

  • Added properties to standalone.xml

    <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
    <property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
    <property name="file.encoding" value="UTF-8"/>
    
  • Logs in console when debugging request parameters from filter

    index_form:people: Tischner PrzemysÅaw

    index_form:j_idt66: index_form:j_idt66

    index_form: index_form

    index_form:dbId: 2881850

    javax.faces.ViewState: 2748560203387116963:2575775533048879716

  • Request preview in browser Request in Chrome

  • How I initialize JSF page

    <f:metadata>
        <f:viewParam name="name" value="#{followNewView.name}" />
        <f:viewParam name="company" value="#{followNewView.company}" />
        <f:viewParam name="companyURL" value="#{followNewView.companyURL}" />
        <f:viewAction action="#{followNewView.init}" />
    </f:metadata>
    

Finally I'm still ending with improper encoding: enter image description here

Was it helpful?

Solution

The problem was in Undertow encoding.

Solution here: https://issues.jboss.org/browse/WFLY-2533

OTHER TIPS

here is a Bug about this:

https://issues.jboss.org/browse/WFLY-2550

and here is one possible solution:

add this after your filter in web.xml:

<filter-mapping>
    <filter-name>CDI Conversation Filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

as described here:

http://weld.cdi-spec.org/documentation/#3

Regards,

Martin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top