1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| package space.terwer.struts23;
import java.util.Calendar; import java.util.Date;
import com.opensymphony.xwork2.ActionSupport;
public class RegisterAction extends ActionSupport { private String username; private String password; private String repassword; private Integer age; private Date birthday; private Date graduation;
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
public String getPassword() { return password; }
public void setPassword(String password) { this.password = password; }
public String getRepassword() { return repassword; }
public void setRepassword(String repassword) { this.repassword = repassword; }
public Integer getAge() { return age; }
public void setAge(Integer age) { this.age = age; }
public Date getBirthday() { return birthday; }
public void setBirthday(Date birthday) { this.birthday = birthday; }
public Date getGraduation() { return graduation; }
public void setGraduation(Date graduation) { this.graduation = graduation; }
@Override public void validate() {
if (null == this.getUsername() || this.getUsername().length() < 4 || this.getUsername().length() > 6) { this.addActionError("username invalid"); this.addFieldError("username", "username invalid in field"); this.addFieldError("username", "username invalid in field2"); }
if (null == this.getPassword() || this.getPassword().length() < 4 || this.getPassword().length() > 6) { this.addActionError("password invalid"); } else if (null == this.getRepassword() || this.getRepassword().length() < 4 || this.getRepassword().length() > 6) { this.addActionError("repassword invalid"); } else if (!this.getPassword().equals(this.getRepassword())) { this.addActionError("the passwords not same"); }
if (this.getAge() < 10 || this.getAge() > 50) { this.addActionError("age invalid"); }
if (null == this.getBirthday()) { this.addActionError("birthday invalid"); }
if (null == this.getGraduation()) { this.addActionError("graduation invalid"); }
if (null != this.getBirthday() && null != this.getGraduation()) { Calendar c1 = Calendar.getInstance(); c1.setTime(this.getBirthday());
Calendar c2 = Calendar.getInstance(); c2.setTime(this.getGraduation());
if (c1.after(c2)) { this.addActionError("birthday should be before graduation"); } }
System.out.println("error cleared"); }
@Override public String execute() throws Exception { return SUCCESS; } }
|