Friday, February 29, 2008

Strutes2 client side Custem Validations to password confirmation and string equals

Hi ,
Can some body tell me a way to do the password validation in client side by doing a custom validations. It is not possible to check string equal with current one.

any suggestions please.

tnx.

Reply i.

You can do this buy creating a class by extending FieldValidatorSupport as following example
and creating a validator.xml and relevant validation xml as show in the image below.

Example for FieldValidatorSupport extended class,

import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
import com.opensymphony.xwork2.validator.*;

public class EqualsStringValidator extends FieldValidatorSupport {


private String fieldName2;

public String getFieldName2() {
return fieldName2;
}

public void setFieldName2(String fieldName2) {
this.fieldName2 = fieldName2;
}

public void validate(Object o) throws ValidationException {
//
String fieldName = getFieldName();
String fieldName2 = getFieldName2();

System.out.println("fieldName-------->>> " + fieldName);

String val = (String) getFieldValue(fieldName, o);
String val2 = (String) getFieldValue(fieldName2, o);

System.out.println("Val >>" + val + "Val2>>>" + val2);


}

and do the following , click on the image to see it.

2 comments:

SSG said...

Thanks , That help me alot

SSG said...

I hope this is very helpful