Java Code Examples for org.springframework.beans.propertyeditors.CustomDateEditor

The following examples show how to use org.springframework.beans.propertyeditors.CustomDateEditor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: BindTagTests.java    License: MIT License 6 votes vote down vote up
@Test
public void transformTagNonExistingValue() throws JspException {
	// first set up the pagecontext and the bean
	PageContext pc = createPageContext();
	TestBean tb = new TestBean();
	DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "tb");
	CustomDateEditor l = new CustomDateEditor(df, true);
	binder.registerCustomEditor(Date.class, l);
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", binder.getBindingResult());

	// try with non-existing value
	BindTag bind = new BindTag();
	bind.setPageContext(pc);
	bind.setPath("tb.name");
	bind.doStartTag();

	TransformTag transform = new TransformTag();
	transform.setPageContext(pc);
	transform.setValue(null);
	transform.setParent(bind);
	transform.setVar("theString2");
	transform.doStartTag();

	assertNull(pc.getAttribute("theString2"));
}
 
Example 2
Source Project: java-technology-stack   Source File: BindTagTests.java    License: MIT License 6 votes vote down vote up
@Test
public void transformTagNonExistingValue() throws JspException {
	// first set up the pagecontext and the bean
	PageContext pc = createPageContext();
	TestBean tb = new TestBean();
	DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "tb");
	CustomDateEditor l = new CustomDateEditor(df, true);
	binder.registerCustomEditor(Date.class, l);
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", binder.getBindingResult());

	// try with non-existing value
	BindTag bind = new BindTag();
	bind.setPageContext(pc);
	bind.setPath("tb.name");
	bind.doStartTag();

	TransformTag transform = new TransformTag();
	transform.setPageContext(pc);
	transform.setValue(null);
	transform.setParent(bind);
	transform.setVar("theString2");
	transform.doStartTag();

	assertNull(pc.getAttribute("theString2"));
}
 
Example 3
@InitBinder
public void initBinder(WebDataBinder binder,
		@RequestParam("date-pattern") Optional<String> optionalPattern) {

	optionalPattern.ifPresent(pattern -> {
		CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(pattern), false);
		binder.registerCustomEditor(Date.class, dateEditor);
	});
}
 
Example 4
@InitBinder
public void initBinder(WebDataBinder binder, @PathVariable("hotel") String hotel) {
	assertEquals("Invalid path variable value", "42", hotel);
	binder.initBeanPropertyAccess();
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
 
Example 5
@InitBinder
public void initBinder(WebDataBinder binder) {
	binder.initBeanPropertyAccess();
	binder.setRequiredFields("sex");
	LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
	vf.afterPropertiesSet();
	binder.setValidator(vf);
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
 
Example 6
@InitBinder({"myCommand", "date"})
public void initBinder(WebDataBinder binder, String date, @RequestParam("date") String[] date2) {
	LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
	vf.afterPropertiesSet();
	binder.setValidator(vf);
	assertEquals("2007-10-02", date);
	assertEquals(1, date2.length);
	assertEquals("2007-10-02", date2[0]);
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
 
Example 7
@Override
public void initBinder(WebDataBinder binder) {
	LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
	vf.afterPropertiesSet();
	binder.setValidator(vf);
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
 
Example 8
@InitBinder
public void initBinder(WebDataBinder binder) {
	binder.initBeanPropertyAccess();
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
 
Example 9
Source Project: spring-analysis-note   Source File: BindTagTests.java    License: MIT License 5 votes vote down vote up
@Test
public void transformTagWithHtmlEscape() throws JspException {
	// first set up the PageContext and the bean
	PageContext pc = createPageContext();
	TestBean tb = new TestBean();
	DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "tb");
	CustomDateEditor l = new CustomDateEditor(df, true);
	binder.registerCustomEditor(Date.class, l);
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", binder.getBindingResult());

	// try another time, this time using Strings
	BindTag bind = new BindTag();
	bind.setPageContext(pc);
	bind.setPath("tb.name");
	bind.doStartTag();

	TransformTag transform = new TransformTag();
	transform.setPageContext(pc);
	transform.setValue("na<me");
	transform.setParent(bind);
	transform.setVar("theString");
	transform.setHtmlEscape(true);
	transform.doStartTag();

	assertNotNull(pc.getAttribute("theString"));
	assertEquals("na&lt;me", pc.getAttribute("theString"));
}
 
Example 10
Source Project: spring-analysis-note   Source File: ConcurrentBeanFactoryTests.java    License: MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
			qualifiedResource(ConcurrentBeanFactoryTests.class, "context.xml"));

	factory.addPropertyEditorRegistrar(
			registry -> registry.registerCustomEditor(Date.class,
					new CustomDateEditor((DateFormat) DATE_FORMAT.clone(), false)));

	this.factory = factory;
}
 
Example 11
Source Project: pcf-crash-course-with-spring-boot   Source File: TodoController.java    License: MIT License 5 votes vote down vote up
@InitBinder
public void initBinder(WebDataBinder binder) {
	// Date - dd/MM/yyyy
	SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	binder.registerCustomEditor(Date.class, new CustomDateEditor(
			dateFormat, false));
}
 
Example 12
Source Project: pcf-crash-course-with-spring-boot   Source File: TodoController.java    License: MIT License 5 votes vote down vote up
@InitBinder
public void initBinder(WebDataBinder binder) {
	// Date - dd/MM/yyyy
	SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	binder.registerCustomEditor(Date.class, new CustomDateEditor(
			dateFormat, false));
}
 
Example 13
Source Project: kubernetes-crash-course   Source File: TodoController.java    License: MIT License 5 votes vote down vote up
@InitBinder
public void initBinder(WebDataBinder binder) {
	// Date - dd/MM/yyyy
	SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	binder.registerCustomEditor(Date.class, new CustomDateEditor(
			dateFormat, false));
}
 
Example 14
Source Project: kubernetes-crash-course   Source File: TodoController.java    License: MIT License 5 votes vote down vote up
@InitBinder
public void initBinder(WebDataBinder binder) {
	// Date - dd/MM/yyyy
	SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	binder.registerCustomEditor(Date.class, new CustomDateEditor(
			dateFormat, false));
}
 
Example 15
Source Project: docker-crash-course   Source File: TodoController.java    License: MIT License 5 votes vote down vote up
@InitBinder
public void initBinder(WebDataBinder binder) {
	// Date - dd/MM/yyyy
	SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	binder.registerCustomEditor(Date.class, new CustomDateEditor(
			dateFormat, false));
}
 
Example 16
Source Project: docker-crash-course   Source File: TodoController.java    License: MIT License 5 votes vote down vote up
@InitBinder
public void initBinder(WebDataBinder binder) {
	// Date - dd/MM/yyyy
	SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	binder.registerCustomEditor(Date.class, new CustomDateEditor(
			dateFormat, false));
}
 
Example 17
@InitBinder
public void initBinder(WebDataBinder binder,
		@RequestParam("date-pattern") Optional<String> optionalPattern) {

	optionalPattern.ifPresent(pattern -> {
		CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(pattern), false);
		binder.registerCustomEditor(Date.class, dateEditor);
	});
}
 
Example 18
@InitBinder
public void initBinder(WebDataBinder binder, @PathVariable("hotel") String hotel) {
	assertEquals("Invalid path variable value", "42", hotel);
	binder.initBeanPropertyAccess();
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
 
Example 19
@InitBinder
public void initBinder(WebDataBinder binder) {
	binder.initBeanPropertyAccess();
	binder.setRequiredFields("sex");
	LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
	vf.afterPropertiesSet();
	binder.setValidator(vf);
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
 
Example 20
@InitBinder({"myCommand", "date"})
public void initBinder(WebDataBinder binder, String date, @RequestParam("date") String[] date2) {
	LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
	vf.afterPropertiesSet();
	binder.setValidator(vf);
	assertEquals("2007-10-02", date);
	assertEquals(1, date2.length);
	assertEquals("2007-10-02", date2[0]);
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
 
Example 21
@Override
public void initBinder(WebDataBinder binder) {
	LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
	vf.afterPropertiesSet();
	binder.setValidator(vf);
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
 
Example 22
@InitBinder
public void initBinder(WebDataBinder binder) {
	binder.initBeanPropertyAccess();
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
 
Example 23
Source Project: java-technology-stack   Source File: BindTagTests.java    License: MIT License 5 votes vote down vote up
@Test
public void transformTagWithHtmlEscape() throws JspException {
	// first set up the PageContext and the bean
	PageContext pc = createPageContext();
	TestBean tb = new TestBean();
	DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "tb");
	CustomDateEditor l = new CustomDateEditor(df, true);
	binder.registerCustomEditor(Date.class, l);
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", binder.getBindingResult());

	// try another time, this time using Strings
	BindTag bind = new BindTag();
	bind.setPageContext(pc);
	bind.setPath("tb.name");
	bind.doStartTag();

	TransformTag transform = new TransformTag();
	transform.setPageContext(pc);
	transform.setValue("na<me");
	transform.setParent(bind);
	transform.setVar("theString");
	transform.setHtmlEscape(true);
	transform.doStartTag();

	assertNotNull(pc.getAttribute("theString"));
	assertEquals("na&lt;me", pc.getAttribute("theString"));
}
 
Example 24
Source Project: java-technology-stack   Source File: ConcurrentBeanFactoryTests.java    License: MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);

	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CONTEXT);
	factory.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
		@Override
		public void registerCustomEditors(PropertyEditorRegistry registry) {
			registry.registerCustomEditor(Date.class, new CustomDateEditor((DateFormat) DATE_FORMAT.clone(), false));
		}
	});
	this.factory = factory;
}
 
Example 25
public void initBinder(WebDataBinder binder) {  
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");   
      dateFormat.setLenient(false);   
      binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));   
   //   binder.registerCustomEditor(String.class, new StringTrimmerEditor(false)); 

  }
 
Example 26
Source Project: SA47   Source File: StaffController.java    License: The Unlicense 5 votes vote down vote up
@InitBinder("course")
private void initCourseBinder(WebDataBinder binder) {
	SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
	binder.addValidators(cValidator);

}
 
Example 27
/**
 * 局部日期转换,将 String 类型的时间数据转化为 Date 类型
 * @param binder
 * @param request
 */
@InitBinder
   public void initBinder(WebDataBinder binder, WebRequest request) {
       // 转换日期 注意这里的转化要和传进来的字符串的格式一直 如2015-9-9 就应该为yyyy-MM-dd
       DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
       // CustomDateEditor为自定义日期编辑器
       binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
   }
 
Example 28
@Override
public void initBinder(WebDataBinder binder, WebRequest request) {
	// 转换日期,注意这里的转化要和传进来的字符串的格式一直 如 2015-9-9 就应该为 yyyy-MM-dd
	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	// CustomDateEditor 为自定义日期编辑器
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
 
Example 29
Source Project: xmanager   Source File: BaseController.java    License: Apache License 2.0 5 votes vote down vote up
@InitBinder
public void initBinder(ServletRequestDataBinder binder) {
    /**
     * 自动转换日期类型的字段格式
     */
    binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true));
    /**
     * 防止XSS攻击
     */
    binder.registerCustomEditor(String.class, new StringEscapeEditor());
}
 
Example 30
Source Project: xmanager   Source File: BaseController.java    License: Apache License 2.0 5 votes vote down vote up
@InitBinder
public void initBinder(ServletRequestDataBinder binder) {
    /**
     * 自动转换日期类型的字段格式
     */
    binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true));
    /**
     * 防止XSS攻击
     */
    binder.registerCustomEditor(String.class, new StringEscapeEditor());
}