jeudi 6 mars 2014

Two ajax action on the same time


Vote count:

0




I want to validate Strengh Password ,and Confirm identic Password in my JSF form on the same time using Ajax I have a problem on displaying a different message for each action


Here my JSF code



<h:form>
<h:outputLabel for="password" value="Password:" />
<h:inputSecret id="password" value="#{marchand.motpass}" validatorMessage="Mot de passe faible" required="true">
<f:ajax event="keyup" render="message_validate_password" />
<f:ajax event="blur" execute="@this password confirm" render="m_password" /> <f:validateRegex pattern="^(?=.*[A-Z])(?=.*[!@#*&amp;$])(?=.*[0-9])(?=.*[a-z]).{8,}$" /> <f:validator validatorId="confirmPasswordValidator" />
<f:attribute name="confirm" value="#{confirmPassword.submittedValue}" />
</h:inputSecret> <h:message id="m_password" for="password" /> <h:message id="message_validate_password" for="password"/>
<h:outputLabel for="confirm" value="Password (again):" />
<h:inputSecret id="confirm" binding="#{confirmPassword}" required="true">
<f:ajax event="blur" execute="@this password" render="m_password m_confirm" /> </h:inputSecret> <h:message id="m_confirm" for="confirm" />
</h:form>


Code of validating identic passwords



@FacesValidator("confirmPasswordValidator")
public class confirmpass implements Validator{
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
String password = (String) value;
String confirm = (String) component.getAttributes().get("confirm");
if (password == null || confirm == null) {
return;
// Just ignore and let required="true" do its job.
} if (!password.equals(confirm))
{ throw new ValidatorException(
new FacesMessage("Passwords are not equal.")); } } }


asked 2 mins ago






Aucun commentaire:

Enregistrer un commentaire