解决方案 »
- DispatchAction问题
- 使用接口和继承的问题
- 请问怎样把JBuild工程导入到Eclips中或Eclips工程导入到JBuild中
- 我是做JSP网站的,想用我们公司服务器挂别人网站接私活!~不知道怎么才可以接到!~
- Cannot find bean ** in any scope(高分)
- 像CSDN左边的树形结构的问题!!!
- 初学者问题:关于建Servlet文件
- JSP是不是就是用各种元素将Bean的结果返回给用户
- jdbc连接oracle9.0的问题
- 以前没人提问过的Linux下apache+tomcat问题
- 单独的JSP文件用什么才能打开?如何配置???
- 有没有方法判断。一 个字符是不是一个字符数组里的成员的方法啊
public void validate(ValidationContext ctx) {
//all the bean properties
Map<String,Property> beanProps = ctx.getProperties(ctx.getProperty().getBase());
//first let's check the passwords match
validatePasswords(ctx, (String)beanProps.get("password").getValue(), (String)ctx.getValidatorArg("retypedPassword"));
validateAge(ctx, (Integer)beanProps.get("age").getValue());
validateWeight(ctx, (Double)beanProps.get("weight").getValue());
validateEmail(ctx, (String)beanProps.get("email").getValue());
validateCaptcha(ctx, (String)ctx.getValidatorArg("captcha"), (String)ctx.getValidatorArg("captchaInput"));
}
private void validatePasswords(ValidationContext ctx, String password, String retype) {
if(password == null || retype == null || (!password.equals(retype))) {
this.addInvalidMessage(ctx, "password", "Your passwords do not match!");
}
}
private void validateAge(ValidationContext ctx, int age) {
if(age <= 0) {
this.addInvalidMessage(ctx, "age", "Your age should be > 0!");
}
}
private void validateWeight(ValidationContext ctx, double weight) {
if(weight <= 0) {
this.addInvalidMessage(ctx, "weight", "Your weight should be > 0!");
}
}
private void validateEmail(ValidationContext ctx, String email) {
if(email == null || !email.matches(".+@.+\\.[a-z]+")) {
this.addInvalidMessage(ctx, "email", "Please enter a valid email!");
}
}
private void validateCaptcha(ValidationContext ctx, String captcha, String captchaInput) {
if(captchaInput == null || !captcha.equals(captchaInput)) {
this.addInvalidMessage(ctx, "captcha", "The captcha doesn't match!");
}
}
}