struts2--Invalid field value for field不显示--类型错误时候,依然完成提交

来源:百度知道 编辑:UC知道 时间:2024/05/15 16:14:14
struts2验证的时候 为什么类型转换错误的时候不提示呢?
我用了struts的标签库。但是我自己重写的validate()方法中的错误提示信息却都显示了。
如果类型转换错误,应该框架自己显示啊?正常的应该提示Invalid field value for field“”?
代码:
public class RegisterAction extends ActionSupport {

String username;
String password;
String repassword;
int age;
Date startDate;
Date endDate;

============
中间是get和set方法,略了,自动生成的!
=============

public String execute() throws Exception {
System.out.println("RegisterAction.execute()");
return this.SUCCESS;
}

public void validate() {
System.out.println("RegisterAction.validate()");

if(null == username || username.trim().length() <5 || username.trim().length()>12) {
this.addFieldError("username", "用户名的长度应为5-12");
}

if(null == password || password.trim().length() <5) {
this.addFieldError("password", "密码的长度应为5-12&q

希望我说的这么一点东西能给楼主一定的帮助
我记得在学转换器 的时候,有一个框架提供的转换,另外还有自己设置的转换方式
不知道楼主是用的是哪个
另外估计楼主应该使自己配置的吧,
抛出的是TypeConversionExceptio的异常吧
下面的是在学的时候,写的,现在有点既不清楚了
沾上了
看看能否帮助你,要是没什么用,那么就希望吸引来更多的大侠们来共同解决
private Circle parseCircle(String userString) throws TypeConversionException{
Circle circle = null;
int radiusIndex = userString.indexOf("r") + 1;
if(!userString.startsWith("C:r"))
throw new TypeConversionException("Invalid Syntax");
int radius;
try{
radius = Integer.parseInt(userString.substring(radiusIndex));
}catch(NumberFormatException e){
throw new TypeConversionException("Invalid Integer Value for Radius");
}
circle = new Circle();
circle.setRadius(radius);
return circle;
}