@Test public void shouldReturnFormattedDateWhenDataValue() throws Exception { WebDataBinder dataBinder = new WebDataBinder(null); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateString = "2015-10-01 12:00:00"; Date value = dateFormat.parse(dateString); controller.initBinder(dataBinder); CustomDateEditor editor = (CustomDateEditor) dataBinder.findCustomEditor (Date.class, null); editor.setValue(value); String parsedDate = editor.getAsText(); assertThat(dateString, is(parsedDate)); }
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat(DateUtil.FORMAT_DATE_TIME); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
SimpleTableController extends BaseController { @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat(DateUtil.FORMAT_DATE_TIME); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); } }
SimpleTableController extends BaseController { @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat(DateUtil.FORMAT_DATE_TIME); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }  }
SimpleTableController extends BaseController { @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat(DateUtil.FORMAT_DATE_TIME); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }  @RequestMapping(value = "/requisition-report", method = GET, headers = BaseController.ACCEPT_JSON) ResponseEntity<OpenLmisResponse> requisitionReport(
					@RequestParam (value = "startTime", required = true) Date startTime,
					@RequestParam(value = "endTime", required = true) Date endTime); @RequestMapping(value = "/single-product-report", method = GET, headers = BaseController.ACCEPT_JSON) ResponseEntity<OpenLmisResponse> singleProductReport(
			@RequestParam(value = "geographicZoneId", required = false) Long geographicZoneId,
			@RequestParam(value = "productId") final Long productId,
			@RequestParam(value = "endTime", required = false) final Date endTime); @RequestMapping(value = "/all-products-report",method = GET,headers = BaseController.ACCEPT_JSON) ResponseEntity<OpenLmisResponse> allProductsReport(
			@RequestParam(value = "facilityId",required = true) Long facilityId,
			@RequestParam(value = "endTime", required = false) final Date endTime); @InitBinder void initBinder(WebDataBinder binder); }
SimpleTableController extends BaseController { @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat(DateUtil.FORMAT_DATE_TIME); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }  @RequestMapping(value = "/requisition-report", method = GET, headers = BaseController.ACCEPT_JSON) ResponseEntity<OpenLmisResponse> requisitionReport(
					@RequestParam (value = "startTime", required = true) Date startTime,
					@RequestParam(value = "endTime", required = true) Date endTime); @RequestMapping(value = "/single-product-report", method = GET, headers = BaseController.ACCEPT_JSON) ResponseEntity<OpenLmisResponse> singleProductReport(
			@RequestParam(value = "geographicZoneId", required = false) Long geographicZoneId,
			@RequestParam(value = "productId") final Long productId,
			@RequestParam(value = "endTime", required = false) final Date endTime); @RequestMapping(value = "/all-products-report",method = GET,headers = BaseController.ACCEPT_JSON) ResponseEntity<OpenLmisResponse> allProductsReport(
			@RequestParam(value = "facilityId",required = true) Long facilityId,
			@RequestParam(value = "endTime", required = false) final Date endTime); @InitBinder void initBinder(WebDataBinder binder);  }