title: Sending UTF-8 message to JSF page
body: <p>I want to send a message to a JSF page with <code>UTF-8</code> format, but the <code>&lt;p:message&gt;</code> doesn't show correct characters.<br>
  I'm using Tomcat 8.0.28, JSF 2 and Spring.<br>
  JSF page:</p>
  
  <pre><code>&lt;h:form id="loginForm"&gt;
       &lt;p:messages id="messages" style="color:red;margin:8px;" autoUpdate="true"/&gt;
       &lt;p:outputLabel value="Username:"/&gt;
       &lt;p:inputText id="usernameInput" value="#{userMgmtBean.username}"/&gt;
       &lt;p:outputLabel value="Password:"/&gt;
       &lt;h:inputSecret id="passwordInput" value="#{userMgmtBean.password}"/&gt;
       &lt;p:commandButton value="Login" action="#{userMgmtBean.authenticate}"/&gt;
  &lt;/h:form&gt;  
  </code></pre>
  
  <p>java Bean method:</p>
  
  <pre><code>public String authenticate(){
  
      String username = this.username;
      String password = Hash.createHash(this.password);
      FacesContext context = FacesContext.getCurrentInstance();
  
      if(username != null &amp;&amp; password != null &amp;&amp; !username.equals("")) {
          for (int i = 0; i &lt; users.size(); i++) {
              if (users.get(i).getUsername().equals(username) &amp;&amp; users.get(i).getPassword().equals(password)) {
                  Timestamp lastLogin = users.get(i).getLastLogin();
                  int numberOfLogin = users.get(i).getNumberOfLogin();
  
                  users.get(i).setNumberOfLogin(++numberOfLogin);
                  users.get(i).setLastLogin(Timestamp.valueOf(LocalDateTime.now()));
                  service.update(users.get(i));
  
                  context.getExternalContext().getSessionMap().put("username", username);
                  context.getExternalContext().getSessionMap().put("numberOfLogin", numberOfLogin);
                  context.getExternalContext().getSessionMap().put("lastLogin", lastLogin);
                  return "/pages/Home.xhtml?faces-redirect=true";
              }
          }
      }
  
      context.addMessage(null, new FacesMessage("نام کاربری یا رمز عبور اشتباه است!"));
      return null;
  }  
  </code></pre>
  
  <p>And this is what I get:
  <code>��� �����? ?� ��� ���� ������ ���!</code>  </p>
  
  <p>I also guess that the problem is about <code>FacesContext</code> not  <code>&lt;p:message&gt;</code>   </p>
  
  <p><strong>I've tried these solutions before:</strong><br>
  <a href="https://stackoverflow.com/questions/7245835/how-to-set-jsf-message-encoding-to-utf-8">How to set JSF message encoding to UTF-8?</a><br>
  <a href="https://stackoverflow.com/questions/3645491/i18n-with-utf-8-encoded-properties-files-in-jsf-2-0-appliaction/3646601#3646601">i18n with UTF-8 encoded properties files in JSF 2.0 appliaction</a><br>
  <a href="https://stackoverflow.com/questions/10996205/utf-8-encoding-of-get-parameters-in-jsf">UTF-8 encoding of GET parameters in JSF</a><br>
  But Nothing !!!</p>