JSF 2.1
jsf表格
<h:form>
<h:inputText id="userName" value="#{user.name}" />
<h:inputSecret id="password" value="#{user.password}" />
<h:inputSecret id="passwordConfirm" />
<h:commandButton value="Login" action="#{user.login()}" onclick="checkPassword(this.form)" />
</h:form>
javasctipt相关代码:
function checkPassword(form) {
var password = form[form.id + ":password"].value;
var passwordConfirm = form[form.id + ":passwordConfirm"].value;
if (password == passwordConfirm){
return true;
}else{
alert("Password and password confirm fields don't match");
return false;
}
}
实际发生的事情:
案例1:用户正确填写表格=&gt; login()
方法按预期调用
案例2:用户填写的确认密码错误=&gt;将出现alert
对话框,当用户单击对话框的“确定”按钮时,即使返回false
,也会调用该方法!
如何避免案例2的行为,即如果密码不匹配,如何防止调用该行为?