title: h:commandButton works from the second click
body: <p>Here is my code:</p>
  
  <pre><code>&lt;h:form&gt;
      &lt;h:messages errorClass="errorMessage" infoClass="infoMessage"
                  warnClass="warnMessage"&gt;&lt;/h:messages&gt;
      &lt;h:panelGroup id="login" layout="block" rendered="#{!securityBean.authorized}"&gt;
          &lt;h:outputText value="login:"/&gt;
          &lt;h:inputText id="username" value="#{securityBean.username}"/&gt;
          &lt;h:outputText value="password:"/&gt;
          &lt;h:inputSecret id="password" value="#{securityBean.password}"/&gt;
          &lt;h:commandButton value="login" action="#{securityBean.login}"/&gt;
      &lt;/h:panelGroup&gt;
  
      &lt;h:panelGroup id="logout" layout="block" rendered="#{securityBean.authorized}"&gt;
          &lt;h:graphicImage id="img" library="img" name="login_success.jpg"/&gt;
          &lt;h:commandButton value="logout" action="#{securityBean.logout}"/&gt;
      &lt;/h:panelGroup&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>here is backing bean methods </p>
  
  <pre><code>    public Object login() throws ServletException {
          HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
          try {
              request.login(username, password);
          } catch (ServletException e) {
              FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "An Error Occured: Login failed", null));
              e.printStackTrace();
          }
          return null;
      }
  
      public Object logout(){
          HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
          if(session != null){
              session.invalidate();
          }
          return null;
      }
      public boolean isAuthorized() {
          return FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal() != null &amp;&amp;
                  FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName() != null &amp;&amp;
                  !FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName().isEmpty();
      }
  </code></pre>
  
  <p>After login, logout button appears, but it works only on the second click. As you can see no ajax is used here, so this <a href="http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentWhichContainsAnotherForm" rel="nofollow">http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentWhichContainsAnotherForm</a> can't help me..
  How can I make it work correct? Thanks in advance.</p>