1 package org.springframework.samples.petclinic.web; 2 3 import java.text.SimpleDateFormat ; 4 import java.util.Date ; 5 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 9 import org.springframework.beans.propertyeditors.CustomDateEditor; 10 import org.springframework.samples.petclinic.Clinic; 11 import org.springframework.validation.BindException; 12 import org.springframework.web.bind.ServletRequestDataBinder; 13 import org.springframework.web.servlet.ModelAndView; 14 import org.springframework.web.servlet.mvc.SimpleFormController; 15 16 22 public abstract class AbstractClinicForm extends SimpleFormController { 23 24 private Clinic clinic; 25 26 public void setClinic(Clinic clinic) { 27 this.clinic = clinic; 28 } 29 30 protected Clinic getClinic() { 31 return clinic; 32 } 33 34 public void afterPropertiesSet() { 35 if (this.clinic == null) { 36 throw new IllegalArgumentException ("'clinic' is required"); 37 } 38 } 39 40 43 protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) { 44 SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd"); 45 dateFormat.setLenient(false); 46 binder.registerCustomEditor(Date .class, new CustomDateEditor(dateFormat, false)); 47 } 48 49 54 protected ModelAndView disallowDuplicateFormSubmission(HttpServletRequest request, HttpServletResponse response) 55 throws Exception { 56 57 BindException errors = getErrorsForNewForm(request); 58 errors.reject("duplicateFormSubmission", "Duplicate form submission"); 59 return showForm(request, response, errors); 60 } 61 62 } 63 | Popular Tags |