1 16 17 18 package org.apache.struts.webapp.example2; 19 20 21 import javax.servlet.http.HttpServletRequest ; 22 import org.apache.struts.action.ActionError; 23 import org.apache.struts.action.ActionErrors; 24 import org.apache.struts.action.ActionForm; 25 import org.apache.struts.action.ActionMapping; 26 27 28 44 45 public final class SubscriptionForm extends ActionForm { 46 47 48 50 51 54 private String action = "Create"; 55 56 57 60 private boolean autoConnect = false; 61 62 63 66 private String host = null; 67 68 69 72 private String password = null; 73 74 75 78 private String type = null; 79 80 81 84 private String username = null; 85 86 87 89 90 93 public String getAction() { 94 95 return (this.action); 96 97 } 98 99 100 105 public void setAction(String action) { 106 107 this.action = action; 108 109 } 110 111 112 115 public boolean getAutoConnect() { 116 117 return (this.autoConnect); 118 119 } 120 121 122 127 public void setAutoConnect(boolean autoConnect) { 128 129 this.autoConnect = autoConnect; 130 } 131 132 133 136 public String getHost() { 137 138 return (this.host); 139 140 } 141 142 143 148 public void setHost(String host) { 149 150 this.host = host; 151 152 } 153 154 155 158 public String getPassword() { 159 160 return (this.password); 161 162 } 163 164 165 170 public void setPassword(String password) { 171 172 this.password = password; 173 174 } 175 176 177 180 public String getType() { 181 182 return (this.type); 183 184 } 185 186 187 192 public void setType(String type) { 193 194 this.type = type; 195 196 } 197 198 199 202 public String getUsername() { 203 204 return (this.username); 205 206 } 207 208 209 214 public void setUsername(String username) { 215 216 this.username = username; 217 218 } 219 220 221 223 224 230 public void reset(ActionMapping mapping, HttpServletRequest request) { 231 232 this.action = "Create"; 233 this.autoConnect = false; 234 this.host = null; 235 this.password = null; 236 this.type = null; 237 this.username = null; 238 239 } 240 241 242 252 public ActionErrors validate(ActionMapping mapping, 253 HttpServletRequest request) { 254 255 ActionErrors errors = new ActionErrors(); 256 257 if ((host == null) || (host.length() < 1)) 258 errors.add("host", 259 new ActionError("error.host.required")); 260 if ((username == null) || (username.length() < 1)) 261 errors.add("username", 262 new ActionError("error.username.required")); 263 if ((password == null) || (password.length() < 1)) 264 errors.add("password", 265 new ActionError("error.password.required")); 266 if ((type == null) || (type.length() < 1)) 267 errors.add("type", 268 new ActionError("error.type.required")); 269 else if (!"imap".equals(type) && !"pop3".equals(type)) 270 errors.add("type", 271 new ActionError("error.type.invalid", type)); 272 273 return (errors); 274 275 } 276 277 278 } 279 280 | Popular Tags |