title: How to show message in jsf 2?
body: <p>In the login.xhml page i have this code:</p>
  
  <pre><code>&lt;h:inputText id="it1" value="#{requestScope.bestGuess}"/&gt;
  &lt;p /&gt;
  &lt;h:message for="it1" /&gt;
  &lt;p /&gt;
  &lt;h:commandButton value="try" id="cb1" actionListener="#   {LoginBean.verifyAnswer}" Submit="true" immediate="false"/&gt;
  </code></pre>
  
  <p>and this code in LoginBean :</p>
  
  <pre><code>public class LoginBean {
      public void verifyAnswer(ActionEvent actionEvent) {
          FacesContext fctx = FacesContext.getCurrentInstance();
          ExternalContext ectx =  fctx.getExternalContext();
          HttpServletRequest request = (HttpServletRequest) ectx.getRequest();
          Captcha captcha = (Captcha) ectx.getSessionMap().get(Captcha.NAME);
          try {
            request.setCharacterEncoding("UTF-8");
          } catch (UnsupportedEncodingException e) {
            //bad luck - but ignore
            System.out.println("UTF not supported !");
          }
          String answer = (String) ectx.getRequestMap().get("bestGuess");
          if (answer != null &amp;&amp; captcha.isCorrect(answer)){
            /*message("Hello, Human");*/
            fctx.addMessage("it1",new FacesMessage("Hello, Human"));
          }
          else{
            /*message("Hello Mr. Roboto. Try again.");*/
            fctx.addMessage("it1",new FacesMessage("Hello Mr. Roboto. Try again."));
          }
        }  
  }
  </code></pre>
  
  <p>How to show message when cpatcha? 
  for example :  cpatcha true show "Hello, Human" or cpatcha false show "Hello Mr. Roboto. Try again."</p>