org.springframework.web.bind.ServletRequestDataBinder Java Examples

The following examples show how to use org.springframework.web.bind.ServletRequestDataBinder. 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   Author: Vip-Augus   File: ExtendedServletRequestDataBinderTests.java    License: MIT License 6 votes vote down vote up
@Test
public void uriTemplateVarAndRequestParam() throws Exception {
	request.addParameter("age", "35");

	Map<String, String> uriTemplateVars = new HashMap<>();
	uriTemplateVars.put("name", "nameValue");
	uriTemplateVars.put("age", "25");
	request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);

	TestBean target = new TestBean();
	WebDataBinder binder = new ExtendedServletRequestDataBinder(target, "");
	((ServletRequestDataBinder) binder).bind(request);

	assertEquals("nameValue", target.getName());
	assertEquals(35, target.getAge());
}
 
Example #2
Source Project: spring-analysis-note   Author: Vip-Augus   File: BindTagTests.java    License: MIT License 6 votes vote down vote up
@Test
public void bindTagWithoutErrors() throws JspException {
	PageContext pc = createPageContext();
	Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
	BindTag tag = new BindTag();
	tag.setPageContext(pc);
	tag.setPath("tb");
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
	assertTrue("Has status variable", status != null);
	assertTrue("Correct expression", status.getExpression() == null);
	assertTrue("Correct value", status.getValue() == null);
	assertTrue("Correct displayValue", "".equals(status.getDisplayValue()));
	assertTrue("Correct isError", !status.isError());
	assertTrue("Correct errorCodes", status.getErrorCodes().length == 0);
	assertTrue("Correct errorMessages", status.getErrorMessages().length == 0);
	assertTrue("Correct errorCode", "".equals(status.getErrorCode()));
	assertTrue("Correct errorMessage", "".equals(status.getErrorMessage()));
	assertTrue("Correct errorMessagesAsString", "".equals(status.getErrorMessagesAsString(",")));
}
 
Example #3
Source Project: spring-analysis-note   Author: Vip-Augus   File: BindTagTests.java    License: MIT License 6 votes vote down vote up
@Test
public void bindTagWithIndexedProperties() throws JspException {
	PageContext pc = createPageContext();
	IndexedTestBean tb = new IndexedTestBean();
	Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult();
	errors.rejectValue("array[0]", "code1", "message1");
	errors.rejectValue("array[0]", "code2", "message2");
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);

	BindTag tag = new BindTag();
	tag.setPageContext(pc);
	tag.setPath("tb.array[0]");
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
	assertTrue("Has status variable", status != null);
	assertTrue("Correct expression", "array[0]".equals(status.getExpression()));
	assertTrue("Value is TestBean", status.getValue() instanceof TestBean);
	assertTrue("Correct value", "name0".equals(((TestBean) status.getValue()).getName()));
	assertTrue("Correct isError", status.isError());
	assertTrue("Correct errorCodes", status.getErrorCodes().length == 2);
	assertTrue("Correct errorMessages", status.getErrorMessages().length == 2);
	assertTrue("Correct errorCode", "code1".equals(status.getErrorCodes()[0]));
	assertTrue("Correct errorCode", "code2".equals(status.getErrorCodes()[1]));
	assertTrue("Correct errorMessage", "message1".equals(status.getErrorMessages()[0]));
	assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessages()[1]));
}
 
Example #4
Source Project: spring-analysis-note   Author: Vip-Augus   File: BindTagTests.java    License: MIT License 6 votes vote down vote up
@Test
public void bindTagWithMappedProperties() throws JspException {
	PageContext pc = createPageContext();
	IndexedTestBean tb = new IndexedTestBean();
	Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult();
	errors.rejectValue("map[key1]", "code1", "message1");
	errors.rejectValue("map[key1]", "code2", "message2");
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);

	BindTag tag = new BindTag();
	tag.setPageContext(pc);
	tag.setPath("tb.map[key1]");
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
	assertTrue("Has status variable", status != null);
	assertTrue("Correct expression", "map[key1]".equals(status.getExpression()));
	assertTrue("Value is TestBean", status.getValue() instanceof TestBean);
	assertTrue("Correct value", "name4".equals(((TestBean) status.getValue()).getName()));
	assertTrue("Correct isError", status.isError());
	assertTrue("Correct errorCodes", status.getErrorCodes().length == 2);
	assertTrue("Correct errorMessages", status.getErrorMessages().length == 2);
	assertTrue("Correct errorCode", "code1".equals(status.getErrorCodes()[0]));
	assertTrue("Correct errorCode", "code2".equals(status.getErrorCodes()[1]));
	assertTrue("Correct errorMessage", "message1".equals(status.getErrorMessages()[0]));
	assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessages()[1]));
}
 
Example #5
Source Project: spring-analysis-note   Author: Vip-Augus   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 #6
Source Project: java-technology-stack   Author: codeEngraver   File: BindTagTests.java    License: MIT License 6 votes vote down vote up
@Test
public void bindTagWithMappedProperties() throws JspException {
	PageContext pc = createPageContext();
	IndexedTestBean tb = new IndexedTestBean();
	Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult();
	errors.rejectValue("map[key1]", "code1", "message1");
	errors.rejectValue("map[key1]", "code2", "message2");
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);

	BindTag tag = new BindTag();
	tag.setPageContext(pc);
	tag.setPath("tb.map[key1]");
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
	assertTrue("Has status variable", status != null);
	assertTrue("Correct expression", "map[key1]".equals(status.getExpression()));
	assertTrue("Value is TestBean", status.getValue() instanceof TestBean);
	assertTrue("Correct value", "name4".equals(((TestBean) status.getValue()).getName()));
	assertTrue("Correct isError", status.isError());
	assertTrue("Correct errorCodes", status.getErrorCodes().length == 2);
	assertTrue("Correct errorMessages", status.getErrorMessages().length == 2);
	assertTrue("Correct errorCode", "code1".equals(status.getErrorCodes()[0]));
	assertTrue("Correct errorCode", "code2".equals(status.getErrorCodes()[1]));
	assertTrue("Correct errorMessage", "message1".equals(status.getErrorMessages()[0]));
	assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessages()[1]));
}
 
Example #7
Source Project: java-technology-stack   Author: codeEngraver   File: BindTagTests.java    License: MIT License 6 votes vote down vote up
@Test
public void nestedPathWithBindTagWithIgnoreNestedPath() throws JspException {
	PageContext pc = createPageContext();
	Errors errors = new ServletRequestDataBinder(new TestBean(), "tb2").getBindingResult();
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb2", errors);

	NestedPathTag tag = new NestedPathTag();
	tag.setPath("tb");
	tag.setPageContext(pc);
	tag.doStartTag();

	BindTag bindTag = new BindTag();
	bindTag.setPageContext(pc);
	bindTag.setIgnoreNestedPath(true);
	bindTag.setPath("tb2.name");

	assertTrue("Correct doStartTag return value", bindTag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
	assertTrue("Has status variable", status != null);
	assertEquals("tb2.name", status.getPath());
}
 
Example #8
Source Project: java-technology-stack   Author: codeEngraver   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 #9
Source Project: webcurator   Author: DIA-NZ   File: AgencyControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link org.webcurator.ui.admin.controller.AgencyController#initBinder(javax.servlet.http.HttpServletRequest, org.springframework.web.bind.ServletRequestDataBinder)}.
 */
@Test
public final void testInitBinder() {
	MockHttpServletRequest request = new MockHttpServletRequest();
	ServletRequestDataBinder binder = new ServletRequestDataBinder(new AgencyCommand(), "command");
	try
	{
		testInstance.initBinder(request, binder);
	}
	catch (Exception e)
	{
		String message = e.getClass().toString() + " - " + e.getMessage();
		log.debug(message);
		fail(message);
	}
}
 
Example #10
Source Project: webcurator   Author: DIA-NZ   File: SitePermissionHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
	super.initBinder(request, binder);
	
       NumberFormat nf = NumberFormat.getInstance(request.getLocale());	
       
       // Register the binders.
       binder.registerCustomEditor(Long.class, "selectedPermission", new CustomNumberEditor(Long.class, nf, true));
	binder.registerCustomEditor(java.util.Date.class, "startDate", DateUtils.get().getFullDateEditor(true));
	binder.registerCustomEditor(java.util.Date.class, "endDate", DateUtils.get().getFullDateEditor(true));
	
	// If the session model is available, we want to register the Permission's
	// authorising agency editor.
	if(getEditorContext(request) != null) {
		//binder.registerCustomEditor(AuthorisingAgent.class, new PermissionAuthAgencyEditor(sessionModel.getAuthorisingAgents()));
		binder.registerCustomEditor(AuthorisingAgent.class, "authorisingAgent", new EditorContextObjectEditor(getEditorContext(request), AuthorisingAgent.class));
		binder.registerCustomEditor(Set.class, "urls", new UrlPatternCollectionEditor(Set.class, true, getEditorContext(request)));
	}
}
 
Example #11
Source Project: gvnix   Author: gvSIGAssociation   File: Jackson2ServletRequestDataBinderFactory.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Look current Thread for {@link ServletRequestDataBinder} created by
 * {@link DataBinderMappingJackson2HttpMessageConverter}, if found return
 * it, otherwise it delegates on parent method.
 * 
 * @param target
 * @param objectName
 * @param request
 * @return ServletRequestDataBinder
 */
@Override
protected ServletRequestDataBinder createBinderInstance(Object target,
        String objectName, NativeWebRequest request) {
    try {
        ServletRequestDataBinder binder = (ServletRequestDataBinder) ThreadLocalUtil
                .getThreadVariable(BindingResult.MODEL_KEY_PREFIX
                        .concat("JSON_DataBinder"));
        if (binder != null) {
            return binder;
        }
        return super.createBinderInstance(target, objectName, request);
    }
    finally {
        ThreadLocalUtil.destroy();
    }
}
 
Example #12
Source Project: spring4-understanding   Author: langtianya   File: BindTagTests.java    License: 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 #13
Source Project: ankush   Author: Impetus   File: BaseController.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Set up a custom property editor for converting form inputs to real
 * objects.
 *
 * @param request the current request
 * @param binder the data binder
 */
@InitBinder
protected void initBinder(HttpServletRequest request,
		ServletRequestDataBinder binder) {
	binder.registerCustomEditor(Integer.class, null,
			new CustomNumberEditor(Integer.class, null, true));
	binder.registerCustomEditor(Long.class, null, new CustomNumberEditor(
			Long.class, null, true));
	binder.registerCustomEditor(byte[].class,
			new ByteArrayMultipartFileEditor());
	SimpleDateFormat dateFormat = new SimpleDateFormat(
			"yyyy.MM.dd G 'at' HH:mm:ss z");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, null, new CustomDateEditor(
			dateFormat, true));
}
 
Example #14
Source Project: spring4-understanding   Author: langtianya   File: BindTagTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void bindTagWithoutErrors() throws JspException {
	PageContext pc = createPageContext();
	Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
	BindTag tag = new BindTag();
	tag.setPageContext(pc);
	tag.setPath("tb");
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
	assertTrue("Has status variable", status != null);
	assertTrue("Correct expression", status.getExpression() == null);
	assertTrue("Correct value", status.getValue() == null);
	assertTrue("Correct displayValue", "".equals(status.getDisplayValue()));
	assertTrue("Correct isError", !status.isError());
	assertTrue("Correct errorCodes", status.getErrorCodes().length == 0);
	assertTrue("Correct errorMessages", status.getErrorMessages().length == 0);
	assertTrue("Correct errorCode", "".equals(status.getErrorCode()));
	assertTrue("Correct errorMessage", "".equals(status.getErrorMessage()));
	assertTrue("Correct errorMessagesAsString", "".equals(status.getErrorMessagesAsString(",")));
}
 
Example #15
Source Project: spring4-understanding   Author: langtianya   File: BindTagTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void nestedPathWithBindTagWithIgnoreNestedPath() throws JspException {
	PageContext pc = createPageContext();
	Errors errors = new ServletRequestDataBinder(new TestBean(), "tb2").getBindingResult();
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb2", errors);

	NestedPathTag tag = new NestedPathTag();
	tag.setPath("tb");
	tag.setPageContext(pc);
	tag.doStartTag();

	BindTag bindTag = new BindTag();
	bindTag.setPageContext(pc);
	bindTag.setIgnoreNestedPath(true);
	bindTag.setPath("tb2.name");

	assertTrue("Correct doStartTag return value", bindTag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
	assertTrue("Has status variable", status != null);
	assertEquals("tb2.name", status.getPath());
}
 
Example #16
Source Project: spring-analysis-note   Author: Vip-Augus   File: ServletModelAttributeMethodProcessor.java    License: MIT License 5 votes vote down vote up
/**
 * This implementation downcasts {@link WebDataBinder} to
 * {@link ServletRequestDataBinder} before binding.
 * @see ServletRequestDataBinderFactory
 */
@Override
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) {
	ServletRequest servletRequest = request.getNativeRequest(ServletRequest.class);
	Assert.state(servletRequest != null, "No ServletRequest");
	ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
	servletBinder.bind(servletRequest);
}
 
Example #17
Source Project: spring-analysis-note   Author: Vip-Augus   File: ServletRequestDataBinderFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Returns an instance of {@link ExtendedServletRequestDataBinder}.
 */
@Override
protected ServletRequestDataBinder createBinderInstance(
		@Nullable Object target, String objectName, NativeWebRequest request) throws Exception  {

	return new ExtendedServletRequestDataBinder(target, objectName);
}
 
Example #18
Source Project: spring-analysis-note   Author: Vip-Augus   File: ExtendedServletRequestDataBinderTests.java    License: MIT License 5 votes vote down vote up
@Test
public void createBinder() throws Exception {
	Map<String, String> uriTemplateVars = new HashMap<>();
	uriTemplateVars.put("name", "nameValue");
	uriTemplateVars.put("age", "25");
	request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);

	TestBean target = new TestBean();
	WebDataBinder binder = new ExtendedServletRequestDataBinder(target, "");
	((ServletRequestDataBinder) binder).bind(request);

	assertEquals("nameValue", target.getName());
	assertEquals(25, target.getAge());
}
 
Example #19
Source Project: webcurator   Author: DIA-NZ   File: CreateUserControllerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public final void testInitBinder() {
	MockHttpServletRequest request = new MockHttpServletRequest();
	ServletRequestDataBinder binder = new ServletRequestDataBinder(new CreateUserCommand(), "command");
	try
	{
		testInstance.initBinder(request, binder);
	}
	catch (Exception e)
	{
		String message = e.getClass().toString() + " - " + e.getMessage();
		log.debug(message);
		fail(message);
	}
}
 
Example #20
Source Project: webcurator   Author: DIA-NZ   File: TreeToolControllerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public final void testInitBinder() {
	MockHttpServletRequest request = new MockHttpServletRequest();
	ServletRequestDataBinder binder = new ServletRequestDataBinder(new AgencyCommand(), "command");
	try
	{
		testInstance.initBinder(request, binder);
	}
	catch (Exception e)
	{
		String message = e.getClass().toString() + " - " + e.getMessage();
		log.debug(message);
		fail(message);
	}
}
 
Example #21
Source Project: webcurator   Author: DIA-NZ   File: QaIndicatorController.java    License: 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 #22
Source Project: spring-analysis-note   Author: Vip-Augus   File: BindTagTests.java    License: MIT License 5 votes vote down vote up
@Test
public void bindErrorsTagWithoutErrors() throws JspException {
	PageContext pc = createPageContext();
	Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
	BindErrorsTag tag = new BindErrorsTag();
	tag.setPageContext(pc);
	tag.setName("tb");
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.SKIP_BODY);
	assertTrue("Doesn't have errors variable", pc.getAttribute(BindErrorsTag.ERRORS_VARIABLE_NAME) == null);
}
 
Example #23
Source Project: webcurator   Author: DIA-NZ   File: TreeToolControllerAJAXTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public final void testInitBinder() {
	MockHttpServletRequest request = new MockHttpServletRequest();
	ServletRequestDataBinder binder = new ServletRequestDataBinder(new AgencyCommand(), "command");
	try
	{
		testInstance.initBinder(request, binder);
	}
	catch (Exception e)
	{
		String message = e.getClass().toString() + " - " + e.getMessage();
		log.debug(message);
		fail(message);
	}
}
 
Example #24
Source Project: webcurator   Author: DIA-NZ   File: TabbedTargetControllerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public final void testInitBinder() {
	MockHttpServletRequest request = new MockHttpServletRequest();
	ServletRequestDataBinder binder = new ServletRequestDataBinder(new SiteCommand(), "command");
	try
	{
		testInstance.initBinder(request, binder);
	}
	catch (Exception e)
	{
		String message = e.getClass().toString() + " - " + e.getMessage();
		log.debug(message);
		fail(message);
	}
}
 
Example #25
Source Project: webcurator   Author: DIA-NZ   File: TargetInstanceDisplayHandler.java    License: 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 #26
Source Project: java-platform   Author: xiangxik   File: EntityModelAttributeMethodProcessor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This implementation downcasts {@link WebDataBinder} to
 * {@link ServletRequestDataBinder} before binding.
 * 
 * @see ServletRequestDataBinderFactory
 */
@Override
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) {
	ServletRequest servletRequest = request.getNativeRequest(ServletRequest.class);
	ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
	servletBinder.bind(servletRequest);
}
 
Example #27
Source Project: webcurator   Author: DIA-NZ   File: TargetInstanceProfileHandlerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public final void testInitBinder() {
	MockHttpServletRequest request = new MockHttpServletRequest();
	ServletRequestDataBinder binder = new ServletRequestDataBinder(new CreateUserCommand(), "command");
	try
	{
		testInstance.initBinder(request, binder);
	}
	catch (Exception e)
	{
		String message = e.getClass().toString() + " - " + e.getMessage();
		log.debug(message);
		fail(message);
	}
}
 
Example #28
Source Project: webcurator   Author: DIA-NZ   File: SiteController.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
	super.initBinder(request, binder);
	
       NumberFormat nf = NumberFormat.getInstance(request.getLocale());
       binder.registerCustomEditor(Long.class, "siteOid", new CustomNumberEditor(Long.class, nf, true));
}
 
Example #29
Source Project: webcurator   Author: DIA-NZ   File: TargetSchedulesHandler.java    License: 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(Integer.class, "scheduleType", new CustomNumberEditor(Integer.class, nf, true));
      binder.registerCustomEditor(java.util.Date.class, org.webcurator.ui.util.DateUtils.get().getFullDateEditor(true));       
  }
 
Example #30
Source Project: java-technology-stack   Author: codeEngraver   File: ServletRequestDataBinderFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Returns an instance of {@link ExtendedServletRequestDataBinder}.
 */
@Override
protected ServletRequestDataBinder createBinderInstance(
		@Nullable Object target, String objectName, NativeWebRequest request) throws Exception  {

	return new ExtendedServletRequestDataBinder(target, objectName);
}