1 package org.nextime.ion.backoffice.form; 2 3 import java.text.SimpleDateFormat ; 4 import java.util.Date ; 5 6 import javax.servlet.http.HttpServletRequest ; 7 8 import org.apache.struts.action.ActionError; 9 import org.apache.struts.action.ActionErrors; 10 import org.apache.struts.action.ActionForm; 11 import org.apache.struts.action.ActionMapping; 12 13 public class PublishPublicationForm extends ActionForm { 14 15 private String type; 16 private String dateBegin; 17 private String dateEnd; 18 19 22 public ActionErrors myValidate(HttpServletRequest request) { 23 ActionErrors errors = new ActionErrors(); 24 SimpleDateFormat formatter = new SimpleDateFormat ("dd/MM/yyyy"); 25 if (getType() == null) { 26 ActionError error = new ActionError("error.general.missingField"); 27 errors.add("type", error); 28 } else { 29 if (getType().equals("P_D")) { 30 Date dateBegin = null; 31 Date dateEnd = null; 32 try { 33 dateBegin = formatter.parse(getDateBegin()); 34 } catch (Exception e) { 35 ActionError error = 36 new ActionError("error.general.badDate"); 37 errors.add("date", error); 38 } 39 if (dateBegin != null) { 40 try { 41 dateEnd = formatter.parse(getDateEnd()); 42 } catch (Exception e) { 43 ActionError error = 44 new ActionError("error.general.badDate"); 45 errors.add("date", error); 46 } 47 } 48 if (dateBegin != null && dateEnd != null) { 49 if (dateEnd.before(dateBegin)) { 50 ActionError error = 51 new ActionError("error.publishPublication.badEnd"); 52 errors.add("date", error); 53 } 54 } 55 } 56 } 57 return errors; 58 } 59 60 63 public void reset(ActionMapping arg0, HttpServletRequest arg1) { 64 setType(null); 65 setDateBegin(null); 66 setDateEnd(null); 67 } 68 69 73 public String getDateBegin() { 74 return dateBegin; 75 } 76 77 81 public String getDateEnd() { 82 return dateEnd; 83 } 84 85 89 public String getType() { 90 return type; 91 } 92 93 97 public void setDateBegin(String dateBegin) { 98 this.dateBegin = dateBegin; 99 } 100 101 105 public void setDateEnd(String dateEnd) { 106 this.dateEnd = dateEnd; 107 } 108 109 113 public void setType(String type) { 114 this.type = type; 115 } 116 117 } 118 | Popular Tags |