How to verify account without transfer to another page, using jsf, ajax -


i wan login don't transfer page. when click sign in button or link, pass value of username , password server, verify account in database. if account not existed, want show alert or message. how achieve it? people told me should use ajax, how? thanks.

here jsf code sample:

<h:form>     <h:inputtext id="username" required="true"                  value="#{loginmanagedbean.username}" />     <h:inputsecret id="password" required="true"                    value="#{loginmanagedbean.password}" />     <h:commandlink type="submit"                    id="login_button" value="sign in" /> </h:form> 

sorry, forget. use lasted version of jsf.

you can change view code add ajax function :

<h:form id="loginform">     <h:panelgroup rendered="#{not loginmanagedbean.islogged}">         <h:inputtext id="username" required="true" value="#{loginmanagedbean.username}" />         <h:inputsecret id="password" required="true" value="#{loginmanagedbean.password}" />         <h:commandlink id="login_button" value="sign in">             <f:ajax listener="#{loginmanagedbean.onbuttonloginclick}" render="loginform" />         </h:commandlink>     </h:panelgroup>     <h:panelgroup rendered="#{loginmanagedbean.islogged}">         <h:commandlink id="logout_button" value="sign out">             <f:ajax listener="#{loginmanagedbean.onbuttonlogoutclick}" render="loginform" />         </h:commandlink>     </h:panelgroup> </h:form> 

and change bean :

@managedbean @requestscoped public class loginmanagedbean {     private string username;     private string password;      public void setusername(string username)     {         this.username = username;     }      public string getusername()     {         return this.username;     }      public void setpassword(string password)     {         this.password = password;     }      public string getpassword()     {         return this.password;     }      public boolean getislogged()     {         return false;// change verify in session if logged     }      public void onbuttonloginclick(ajaxbehaviorevent event)     {         // login stuff verification, put user in session, etc     }      public void onbuttonlogoutclick(ajaxbehaviorevent event)     {         // logout stuff verification, remove user in session, etc     } } 

note : can add login error messages , show them <h:message />.

more info :

using ajax facelets


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -