Tôi đang cố gắng xác thực hai trường mật khẩu bằng JSF nhưng không tốt cho đến bây giờ, tôi tìm kiếm nó trên google nhưng mọi thứ về JSF 1.2 và khá khó hiểu, tôi đang sử dụng JSF 2.0.Làm cách nào để xác thực hai trường mật khẩu bằng ajax?
Đây là những gì tôi đang làm cho đến nay:
<h:outputLabel for="password" value="Password:" />
<h:inputSecret id="password" value="#{register.user.password}" >
<f:ajax event="blur" listener="#{register.validatePassword}" render="m_password" />
</h:inputSecret>
<rich:message id="m_password" for="password"/>
<h:outputLabel for="password_2" value="Password (again):" />
<h:inputSecret id="password_2" value="#{register.user.password_2}" >
<f:ajax event="blur" listener="#{register.validatePassword}" />
</h:inputSecret>
Đây là cách tôi nó là bộ điều khiển của tôi:
public void validatePassword() {
FacesMessage message;
if (!user.getPassword().equals(user.getPassword_2())){
message = new FacesMessage(FacesMessage.SEVERITY_ERROR, null, "different password");
}else{
message = new FacesMessage(FacesMessage.SEVERITY_INFO, null, "ok");
}
FacesContext.getCurrentInstance().addMessage("form:password", message);
}
Bất kỳ chàng trai ý tưởng?
Điều gì có nghĩa là nó hoạt động nhưng không tốt như vậy? Nó có chậm không? Không chắc tôi hiểu những gì bạn muốn thay đổi và tại sao. – jdias
Hi @ jdias, ý tôi là không hoạt động theo cách mà nó giả sử. Cảm ơn vì điều đó có thể hơi khó hiểu. –