How validate two password fields by ajax?

后端 未结 3 1035
执笔经年
执笔经年 2020-11-27 04:57

I\'m trying to validate two password fields with JSF but no good until now, I search for it on google but everything was about JSF 1.2 and pretty confusing, I\'m using JSF

3条回答
  •  萌比男神i
    2020-11-27 05:42

    With seam 2 you have the component and you don't need to write code. For JSF2 then you have Seam 3 modules, particulary Faces module and Cross-field Form Validation. An example :

    First you have to use the s:validateForm tag:

    
        
                    
        
        
        
        
    
    

    and the corresponding Validator for the password form above would look like this:

    @FacesValidator("PasswordValidator")
    public class PasswordValidator implements Validator
    {
       @Inject
       @InputField
       private String newPassword;
    
       @Inject
       @InputField
       private String confirmPassword;
    
       @Override
       public void validate(final FacesContext context, final UIComponent comp, final Object values) throws ValidatorException
       {
          if (!confirmPassword.equals(newPassword))
          {
             throw new ValidatorException(new FacesMessage("Passwords do not match!"));
          }
       }
    }
    

提交回复
热议问题