2 Replies Latest reply on Feb 1, 2011 9:50 AM by Ara Minosian

    Ajax login implementation:

    Ara Minosian Newbie

      I use this code to implement login / logout functionality. All works fine but I have to click logout twice. Could it be a bug or I use API wrong?

       

       

      <ui:composition>

          <rich:panel id="loginPanel">

              <a4j:outputPanel id="res">

                  <h:form rendered="#{not userBean.loggedIn}">

                      <f:event type="postValidate" listener="#{loginAndPasswordValidationListener.login}"/>

                        <h:outputText value="Login:"/>

                      <h:inputText id="Login" value="#{userBean.login}" required="true" requiredMessage="What is login?"

                                   validatorMessage="Incorrect regexp">

                          <f:validateRegex pattern="^([a-zA-Z0-9_.-]{3,16})$"/>

                      </h:inputText>

                        <h:outputText value="Password:"/>

                      <h:inputSecret id="Pass" value="#{userBean.password}" required="true" requiredMessage="What is password?"

                                     validatorMessage="Incorrect regexp">

                          <f:validateRegex pattern="^([a-zA-Z0-9_.-]{3,16})$"/>

                      </h:inputSecret>

                          <a4j:commandButton value="Enter" render=":res, :mainmenu" actionListener="#{operator.loginAction}"/>

                          <h:link id="linkToReg" outcome="registration" includeViewParams="true" value="Registration">

                          <f:param name="skin" value="#{skinBean.skin}"/>

                      </h:link>

                      <h:messages/>

                  </h:form>

                    <h:form rendered="#{userBean.loggedIn}">

                      <h:outputText value="#{userBean.login} "/>

                      <a4j:commandButton value="Logout" render=":res, :mainmenu" actionListener="#{operator.logoutAction}"/>

                  </h:form>

              </a4j:outputPanel>

          </rich:panel>

      </ui:composition>

        • 2. Ajax login implementation:
          Ara Minosian Newbie

          Thank you very much Ilya. The problem is in two forms. Correct code:

          <ui:composition>

              <rich:panel id="loginPanel">

                  <h:form>

                      <a4j:outputPanel id="loginpanel">

                          <f:event type="postValidate" listener="#{loginAndPasswordValidationListener.login}"/>

           

           

                          <h:outputText value="Login:" rendered="#{not userBean.loggedIn}"/>

                          <h:inputText id="Login" value="#{userBean.login}" required="true" requiredMessage="What is login?"

                                       rendered="#{not userBean.loggedIn}"

                                       validatorMessage="Regexp error">

                              <f:validateRegex pattern="^([a-zA-Z0-9_.-]{3,16})$"/>

                          </h:inputText>

           

           

                          <h:outputText value="Password:" rendered="#{not userBean.loggedIn}"/>

                          <h:inputSecret id="Pass" value="#{userBean.password}" rendered="#{not userBean.loggedIn}"

                                         required="true" requiredMessage="What is password?"

                                         validatorMessage="Regexp error">

                              <f:validateRegex pattern="^([a-zA-Z0-9_.-]{3,16})$"/>

                          </h:inputSecret>

           

           

                          <a4j:commandButton value="Enter" rendered="#{not userBean.loggedIn}"

                                             render=":loginpanel, :mainmenu"

                                             actionListener="#{operator.loginAction}"/>

                                <h:link id="linkToReg" rendered="#{not userBean.loggedIn}" outcome="registration"

                                  includeViewParams="true" value="Регистрация">

                              <f:param name="skin" value="#{skinBean.skin}"/>

                          </h:link>

                          <h:messages rendered="#{not userBean.loggedIn}"/>

                          <h:outputText rendered="#{userBean.loggedIn}" value="#{userBean.login} "/>

                          <a4j:commandButton rendered="#{userBean.loggedIn}" value="Out"

                                             render=":loginpanel, :mainmenu"

                                             actionListener="#{operator.logoutAction}"/>

                      </a4j:outputPanel>

                  </h:form>

              </rich:panel>

          </ui:composition>