日期:2014-05-16 浏览次数:20533 次
<h:inputText id="userName" value="#{user.userName}"/> <h:commandButton id="check" onclick="return userExit('rForm:message rForm:userName','rForm:userName rForm:check',this,event);" actionListener="#{manager.checkUser}" value="checkUser" />
function userExit(target,exec,element,event){ if(isNull(document.getElementById("rForm:userName"))){ alert("the userName is null"); document.getElementById("rForm:userName").focus(); return false; } else{ try{ jsf.ajax.request(element, event ,{execute: exec , render: target}); }catch(ex){ alert(ex); } return false; } return true; }
public void checkUser(ActionEvent event){ ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); UserBean register = (UserBean) context.getRequestMap().get("user"); DBibatis db = new DBIbatisImpl(); UserBean dbUser = db.queryByName(register.getUserName()); if(dbUser == null){ //可以使用这个用户名 register.setMessage("you can use this userName"); }else{ register.setMessage("this userName has exit ,please chose another one"); } }