code: public String calculateCharacterEncoding(FacesContext context) {
           ExternalContext extContext = context.getExternalContext();
           Map<String,String> headerMap = extContext.getRequestHeaderMap();
           String contentType = headerMap.get("Content-Type");
           String charEnc = null;
           
           // look for a charset in the Content-Type header first.
           if (null != contentType) {
               // see if this header had a charset
               String charsetStr = "charset=";
               int len = charsetStr.length();
               int idx = contentType.indexOf(charsetStr);
               
               // if we have a charset in this Content-Type header AND it
               // has a non-zero length.
               if (idx != -1 && idx + len < contentType.length()) {
                   charEnc = contentType.substring(idx + len);
               }
           }
           
           // failing that, look in the session for a previously saved one
           if (null == charEnc) {
               if (null != extContext.getSession(false)) {
                   charEnc = (String) extContext.getSessionMap().get(CHARACTER_ENCODING_KEY);
               }
           }
           
           return charEnc;
       }
docs: <p>Returns the correct character encoding to be used for this request.</p>
  
  <p>The following algorithm is employed.</p>
  
  <ul>
  
  <li><p>Examine the <code>Content-Type</code> request header.  If it has
  a <code>charset</code> parameter, extract it and return that as the
  encoding.</p></li>
  
  <li><p>If no <code>charset</code> parameter was found, check for the
  existence of a session by calling {@link ExternalContext#getSession(boolean)}
  passing <code>false</code> as the argument.  If that method returns
  <code>true</code>, get the session Map by calling
  {@link ExternalContext#getSessionMap} and look for a value under the
  key given by the value of the symbolic constant
  {@link ViewHandler#CHARACTER_ENCODING_KEY}.
  If present, return the value, converted to String.</p></li>
  
  <li><p>Otherwise, return <code>null</code></p></li>
  
  </ul>
  
  @since 1.2