List of usage examples for org.springframework.beans.propertyeditors CustomDateEditor CustomDateEditor
public CustomDateEditor(DateFormat dateFormat, boolean allowEmpty, int exactDateLength)
From source file:org.openmrs.module.ejemplomedellin.web.controller.RegisterUserController.java
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(Date.class, new CustomDateEditor(Context.getDateFormat(), true, 10)); }
From source file:org.openmrs.module.programlocation.web.controller.PatientProgramFormController.java
public ModelAndView enroll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String returnPage = request.getParameter("returnPage"); if (returnPage == null) { throw new IllegalArgumentException("must specify a returnPage parameter in a call to enroll()"); }/*from w w w . ja va2 s. co m*/ String patientIdStr = request.getParameter("patientId"); String programIdStr = request.getParameter("programId"); String enrollmentDateStr = request.getParameter("dateEnrolled"); String locationIdStr = request.getParameter("locationId"); String completionDateStr = request.getParameter("dateCompleted"); log.debug("enroll " + patientIdStr + " in " + programIdStr + " on " + enrollmentDateStr); ProgramWorkflowService pws = Context.getService(ProgramWorkflowService.class); // make sure we parse dates the same was as if we were using the initBinder + property editor method CustomDateEditor cde = new CustomDateEditor(Context.getDateFormat(), true, 10); cde.setAsText(enrollmentDateStr); Date enrollmentDate = (Date) cde.getValue(); cde.setAsText(completionDateStr); Date completionDate = (Date) cde.getValue(); Patient patient = Context.getPatientService().getPatient(Integer.valueOf(patientIdStr)); Location location; try { location = Context.getLocationService().getLocation(Integer.valueOf(locationIdStr)); } catch (Exception e) { location = null; } Program program = pws.getProgram(Integer.valueOf(programIdStr)); List<org.openmrs.PatientProgram> pps = pws.getPatientPrograms(patient, program, null, completionDate, enrollmentDate, null, false); if (!pps.isEmpty()) request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Program.error.already"); else { PatientProgram pp = new PatientProgram(); pp.setPatient(patient); pp.setLocation(location); pp.setProgram(program); pp.setDateEnrolled(enrollmentDate); pp.setDateCompleted(completionDate); Context.getProgramWorkflowService().savePatientProgram(pp); } return new ModelAndView(new RedirectView(returnPage)); }
From source file:org.openmrs.notification.web.controller.AlertFormController.java
/** * Allows for Integers to be used as values in input tags. Normally, only strings and lists are * expected// w ww . j a v a 2 s .com * * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest, * org.springframework.web.bind.ServletRequestDataBinder) */ protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); Locale locale = Context.getLocale(); NumberFormat nf = NumberFormat.getInstance(locale); // NumberFormat nf = NumberFormat.getInstance(new Locale("en_US")); binder.registerCustomEditor(java.lang.Integer.class, new CustomNumberEditor(java.lang.Integer.class, nf, true)); binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(Context.getDateFormat(), true, 10)); }
From source file:org.openmrs.module.hr.web.controller.JobTitleController.java
@InitBinder public void initBinder(WebDataBinder binder) { NumberFormat nf = NumberFormat.getInstance(Context.getLocale()); binder.registerCustomEditor(java.lang.Integer.class, new CustomNumberEditor(java.lang.Integer.class, nf, true)); binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(Context.getDateFormat(), true, 10)); binder.registerCustomEditor(org.openmrs.Concept.class, new ConceptEditor()); binder.registerCustomEditor(Location.class, new LocationEditor()); }
From source file:org.openmrs.web.controller.program.PatientProgramFormController.java
public ModelAndView enroll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String returnPage = request.getParameter("returnPage"); if (returnPage == null) { throw new IllegalArgumentException("must specify a returnPage parameter in a call to enroll()"); }/* w w w .jav a2 s. c o m*/ String patientIdStr = request.getParameter("patientId"); String programIdStr = request.getParameter("programId"); String enrollmentDateStr = request.getParameter("dateEnrolled"); String locationIdStr = request.getParameter("locationId"); String completionDateStr = request.getParameter("dateCompleted"); log.debug("enroll " + patientIdStr + " in " + programIdStr + " on " + enrollmentDateStr); ProgramWorkflowService pws = Context.getProgramWorkflowService(); // make sure we parse dates the same was as if we were using the initBinder + property editor method CustomDateEditor cde = new CustomDateEditor(Context.getDateFormat(), true, 10); cde.setAsText(enrollmentDateStr); Date enrollmentDate = (Date) cde.getValue(); cde.setAsText(completionDateStr); Date completionDate = (Date) cde.getValue(); Patient patient = Context.getPatientService().getPatient(Integer.valueOf(patientIdStr)); Location location; try { location = Context.getLocationService().getLocation(Integer.valueOf(locationIdStr)); } catch (Exception e) { location = null; } Program program; try { program = pws.getProgram(Integer.valueOf(programIdStr)); } catch (NumberFormatException e) { request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Program.error.programRequired"); return new ModelAndView(new RedirectView(returnPage)); } if (enrollmentDate == null) { request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Program.error.enrollmentDateRequired"); } else if (!pws.getPatientPrograms(patient, program, null, completionDate, enrollmentDate, null, false) .isEmpty()) { request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Program.error.already"); } else { PatientProgram pp = new PatientProgram(); pp.setPatient(patient); pp.setLocation(location); pp.setProgram(program); pp.setDateEnrolled(enrollmentDate); pp.setDateCompleted(completionDate); // Set any initial states if passed in for (ProgramWorkflow workflow : program.getAllWorkflows()) { String stateIdStr = request.getParameter("initialState." + workflow.getProgramWorkflowId()); if (StringUtils.hasText(stateIdStr)) { Integer stateId = Integer.valueOf(stateIdStr); ProgramWorkflowState state = workflow.getState(stateId); log.debug("Transitioning to state: " + state); pp.transitionToState(state, enrollmentDate); } } try { String message = validateWithErrorCodes(pp); if (message != null) { request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, message); } else { Context.getProgramWorkflowService().savePatientProgram(pp); } } catch (APIException e) { request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, e.getMessage()); } } return new ModelAndView(new RedirectView(returnPage)); }
From source file:org.motechproject.server.omod.web.controller.MessagePatientController.java
@InitBinder public void initBinder(WebDataBinder binder) { String datePattern = "yyyy-MM-dd HH:mm:ss"; SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern); dateFormat.setLenient(false);//from w ww.j ava 2s. c o m binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true, datePattern.length())); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); }
From source file:org.motechproject.server.omod.web.controller.SearchPatientsController.java
@InitBinder public void initBinder(WebDataBinder binder) { String datePattern = "dd/MM/yyyy"; SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern); dateFormat.setLenient(false);// w ww .jav a 2s .co m binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true, datePattern.length())); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); }
From source file:org.openmrs.web.controller.patient.PatientFormController.java
/** * Allows for other Objects to be used as values in input tags. Normally, only strings and lists * are expected//from ww w.j a v a2s . c o m * * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest, * org.springframework.web.bind.ServletRequestDataBinder) */ @Override protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { super.initBinder(request, binder); NumberFormat nf = NumberFormat.getInstance(Context.getLocale()); binder.registerCustomEditor(java.lang.Integer.class, new CustomNumberEditor(java.lang.Integer.class, nf, true)); binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(Context.getDateFormat(), true, 10)); binder.registerCustomEditor(PatientIdentifierType.class, new PatientIdentifierTypeEditor()); binder.registerCustomEditor(Location.class, new LocationEditor()); binder.registerCustomEditor(Concept.class, "civilStatus", new ConceptEditor()); binder.registerCustomEditor(Concept.class, "causeOfDeath", new ConceptEditor()); }
From source file:org.motechproject.server.omod.web.controller.DemoPatientController.java
@InitBinder public void initBinder(WebDataBinder binder) { String datePattern = "dd/MM/yyyy"; SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern); dateFormat.setLenient(false);/*from w w w . j av a 2 s . com*/ binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true, datePattern.length())); String timePattern = MotechConstants.TIME_FORMAT_DELIVERY_TIME; SimpleDateFormat timeFormat = new SimpleDateFormat(timePattern); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, "timeOfDay", new CustomDateEditor(timeFormat, true, timePattern.length())); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); }
From source file:org.motechproject.server.omod.web.controller.PatientController.java
@InitBinder public void initBinder(WebDataBinder binder) { String datePattern = "dd/MM/yyyy"; SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern); dateFormat.setLenient(false);/*from w ww. j av a2 s . co m*/ binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true, datePattern.length())); String timePattern = MotechConstants.TIME_FORMAT_DELIVERY_TIME; SimpleDateFormat timeFormat = new SimpleDateFormat(timePattern); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, "timeOfDay", new CustomDateEditor(timeFormat, true, timePattern.length())); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); }