Java Code Examples for org.springframework.web.bind.ServletRequestDataBinder#registerCustomEditor()

The following examples show how to use org.springframework.web.bind.ServletRequestDataBinder#registerCustomEditor() . 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 File: BindTagTests.java    From spring4-understanding with Apache License 2.0 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 File: EditScheduleController.java    From webcurator with Apache License 2.0 6 votes vote down vote up
@Override
  public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
// Determine the necessary formats.
      NumberFormat nf = NumberFormat.getInstance(request.getLocale());
      
      // Register the binders.
      binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, true));
      binder.registerCustomEditor(Integer.class, "scheduleType", new CustomNumberEditor(Integer.class, nf, true));
      binder.registerCustomEditor(java.util.Date.class, org.webcurator.ui.util.DateUtils.get().getFullDateEditor(true));
      binder.registerCustomEditor(Time.class, new TimeEditor(false));
  }
 
Example 3
Source File: TargetInstanceDisplayHandler.java    From webcurator with Apache License 2.0 5 votes vote down vote up
public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    NumberFormat nf = NumberFormat.getInstance(request.getLocale());        
    binder.registerCustomEditor(java.lang.Long.class, new CustomNumberEditor(java.lang.Long.class, nf, true));
    binder.registerCustomEditor(java.lang.Integer.class, new CustomNumberEditor(java.lang.Integer.class, nf, true));
    binder.registerCustomEditor(java.util.Date.class, DateUtils.get().getFullDateTimeEditor(true));
  
}
 
Example 4
Source File: BaseController.java    From xmanager with 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 5
Source File: RegisteredServiceSimpleFormController.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * Sets the require fields and the disallowed fields from the
 * HttpServletRequest.
 *
 * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest,
 * org.springframework.web.bind.ServletRequestDataBinder)
 */
@Override
protected void initBinder(final HttpServletRequest request,
        final ServletRequestDataBinder binder) throws Exception {
    binder.setRequiredFields(new String[] {"description", "serviceId",
            "name", "allowedToProxy", "enabled", "ssoEnabled",
            "anonymousAccess", "evaluationOrder"});
    binder.setDisallowedFields(new String[] {"id"});
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
}
 
Example 6
Source File: QaIndicatorController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
 protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
 	// enable null values for long and float fields
     NumberFormat nf = NumberFormat.getInstance(request.getLocale());
     NumberFormat floatFormat = new DecimalFormat("##############.##");
     binder.registerCustomEditor(java.lang.Long.class, new CustomNumberEditor(java.lang.Long.class, nf, true));   
     binder.registerCustomEditor(java.lang.Float.class, new CustomNumberEditor(java.lang.Float.class, nf, true));   
}
 
Example 7
Source File: QaIndicatorReportController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
protected void initBinder(HttpServletRequest request,
		ServletRequestDataBinder binder) {
	// enable null values for long and float fields
	NumberFormat nf = NumberFormat.getInstance(request.getLocale());
	NumberFormat floatFormat = new DecimalFormat("##############.##");
	binder.registerCustomEditor(java.lang.Long.class,
			new CustomNumberEditor(java.lang.Long.class, nf, true));
	binder.registerCustomEditor(java.lang.Float.class,
			new CustomNumberEditor(java.lang.Float.class, nf, true));
}
 
Example 8
Source File: TreeToolController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
  public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
// Determine the necessary formats.
      NumberFormat nf = NumberFormat.getInstance(request.getLocale());
      
      // Register the binders.
      binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, true));
      binder.registerCustomEditor(Boolean.class, "propagateDelete", new CustomBooleanEditor(true));
      
      // to actually be able to convert Multipart instance to byte[]
      // we have to register a custom editor (in this case the
      // ByteArrayMultipartEditor
      binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
      // now Spring knows how to handle multipart object and convert them
  }
 
Example 9
Source File: CreateQaIndicatorController.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@Override
public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
	// enable null values for long and float fields
    NumberFormat nf = NumberFormat.getInstance(request.getLocale());
    NumberFormat floatFormat = new DecimalFormat("############.##");
    binder.registerCustomEditor(java.lang.Long.class, new CustomNumberEditor(java.lang.Long.class, nf, true));   
    binder.registerCustomEditor(java.lang.Float.class, new CustomNumberEditor(java.lang.Float.class, floatFormat, true));   
}
 
Example 10
Source File: PostController.java    From stone with GNU General Public License v3.0 4 votes vote down vote up
@InitBinder
public void initBinder(ServletRequestDataBinder binder) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
}
 
Example 11
Source File: AbstractBaseController.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@InitBinder
protected void initBinder(ServletRequestDataBinder binder) {
	binder.registerCustomEditor(String.class, new StringPropertyEditor());
	binder.registerCustomEditor(Date.class, new DateTimePropertyEditor());
}
 
Example 12
Source File: BindTagTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void transformTagCorrectBehavior() 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());

	// execute the bind tag using the date property
	BindTag bind = new BindTag();
	bind.setPageContext(pc);
	bind.setPath("tb.date");
	bind.doStartTag();

	// transform stuff
	TransformTag transform = new TransformTag();
	transform.setPageContext(pc);
	transform.setParent(bind);
	transform.setValue(tb.getDate());
	transform.setVar("theDate");
	transform.doStartTag();

	assertNotNull(pc.getAttribute("theDate"));
	assertEquals(pc.getAttribute("theDate"), df.format(tb.getDate()));

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

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

	assertNotNull(pc.getAttribute("theString"));
	assertEquals("name", pc.getAttribute("theString"));
}
 
Example 13
Source File: CreateRejReasonController.java    From webcurator with Apache License 2.0 4 votes vote down vote up
@Override
public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    NumberFormat nf = NumberFormat.getInstance(request.getLocale());
    binder.registerCustomEditor(java.lang.Long.class, new CustomNumberEditor(java.lang.Long.class, nf, true));   
}
 
Example 14
Source File: BindTagTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * SPR-4022
 */
@SuppressWarnings("serial")
@Test
public void nestingInFormTag() throws JspException {
	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());

	FormTag formTag = new FormTag() {
		@Override
		protected TagWriter createTagWriter() {
			return new TagWriter(new StringWriter());
		}
	};

	String action = "/form.html";
	String commandName = "tb";
	String name = "formName";
	String enctype = "my/enctype";
	String method = "POST";
	String onsubmit = "onsubmit";
	String onreset = "onreset";
	String cssClass = "myClass";
	String cssStyle = "myStyle";
	String acceptCharset = "iso-8859-1";

	formTag.setName(name);
	formTag.setCssClass(cssClass);
	formTag.setCssStyle(cssStyle);
	formTag.setAction(action);
	formTag.setModelAttribute(commandName);
	formTag.setEnctype(enctype);
	formTag.setMethod(method);
	formTag.setOnsubmit(onsubmit);
	formTag.setOnreset(onreset);
	formTag.setAcceptCharset(acceptCharset);

	formTag.setPageContext(pc);
	formTag.doStartTag();

	BindTag bindTag1 = new BindTag();
	bindTag1.setPageContext(pc);
	bindTag1.setPath("date");
	bindTag1.doStartTag();
	bindTag1.doEndTag();

	BindTag bindTag2 = new BindTag();
	bindTag2.setPageContext(pc);
	bindTag2.setPath("tb.date");
	bindTag2.doStartTag();
	bindTag2.doEndTag();

	BindTag bindTag3 = new BindTag();
	bindTag3.setPageContext(pc);
	bindTag3.setPath("tb");
	bindTag3.doStartTag();
	bindTag3.doEndTag();

	formTag.doEndTag();
}
 
Example 15
Source File: ProfileFormCredentialsController.java    From webcurator with Apache License 2.0 4 votes vote down vote up
public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    NumberFormat nf = NumberFormat.getInstance(request.getLocale());
    binder.registerCustomEditor(java.lang.Integer.class, new CustomNumberEditor(java.lang.Integer.class, nf, true));   
}
 
Example 16
Source File: ChangePasswordController.java    From webcurator with Apache License 2.0 4 votes vote down vote up
@Override
public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    NumberFormat nf = NumberFormat.getInstance(request.getLocale());
    binder.registerCustomEditor(java.lang.Long.class, new CustomNumberEditor(java.lang.Long.class, nf, true));   
}
 
Example 17
Source File: AbstractBaseController.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@InitBinder
protected void initBinder(ServletRequestDataBinder binder) {
	binder.registerCustomEditor(String.class, new StringPropertyEditor());
	binder.registerCustomEditor(Date.class, new DateTimePropertyEditor());
}
 
Example 18
Source File: PostController.java    From blog-sharon with Apache License 2.0 4 votes vote down vote up
@InitBinder
public void initBinder(ServletRequestDataBinder binder) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
}
 
Example 19
Source File: BaseController.java    From OneBlog with GNU General Public License v3.0 4 votes vote down vote up
@InitBinder
public void initBinder(ServletRequestDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
 
Example 20
Source File: CargoAdminController.java    From dddsample-core with MIT License 4 votes vote down vote up
@InitBinder
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm"), false));
}