Example usage for org.springframework.beans MutablePropertyValues MutablePropertyValues

List of usage examples for org.springframework.beans MutablePropertyValues MutablePropertyValues

Introduction

In this page you can find the example usage for org.springframework.beans MutablePropertyValues MutablePropertyValues.

Prototype

public MutablePropertyValues(@Nullable List<PropertyValue> propertyValueList) 

Source Link

Document

Construct a new MutablePropertyValues object using the given List of PropertyValue objects as-is.

Usage

From source file:gov.nih.nci.cabig.ctms.web.tabs.DefaultTabConfigurerTest.java

private RootBeanDefinition createTestBeanDef(int id) {
    return new RootBeanDefinition(TestBean.class,
            new MutablePropertyValues(Collections.singletonMap("id", id)));
}

From source file:org.sakaiproject.metaobj.utils.mvc.impl.servlet.ServletRequestBeanDataBinder.java

public void bind(ServletRequest request) {
    // bind normal HTTP parameters
    bind(new ServletRequestParameterPropertyValues(request));

    // bind multipart files
    if (request instanceof MultipartHttpServletRequest) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        bind(new MutablePropertyValues(multipartRequest.getFileMap()));
    }//  w  w  w.  j a  v a 2  s . c o  m
}

From source file:cherry.foundation.validator.MinLengthValidatorTest.java

@Test
public void testOK() {

    Map<String, String> val = new HashMap<>();
    val.put("val0", null);
    val.put("val1", "");
    val.put("val2", "1");
    val.put("val3", "12345");
    val.put("val4", "123456");

    TestDto dto = new TestDto();

    WebDataBinder binder = new WebDataBinder(dto);
    binder.setConversionService(conversionService);
    binder.addValidators(validator);//from ww  w  . j av a 2s.  c o m
    binder.bind(new MutablePropertyValues(val));
    binder.validate();
    BindingResult result = binder.getBindingResult();
    assertEquals(0, result.getErrorCount());
    assertNull(dto.getVal0());
    assertEquals("", dto.getVal1());
    assertEquals("1", dto.getVal2());
    assertEquals("12345", dto.getVal3());
    assertEquals("123456", dto.getVal4());
}

From source file:cherry.foundation.validator.ZipCodeValidatorTest.java

@Test
public void testOK() {

    Map<String, String> val = new HashMap<>();
    val.put("zipCode0", null);
    val.put("zipCode1", "");
    val.put("zipCode2", "1234567");
    val.put("zipCode3", null);
    val.put("zipCode4", "");
    val.put("zipCode5", "123-4567");

    TestDto dto = new TestDto();

    WebDataBinder binder = new WebDataBinder(dto);
    binder.setConversionService(conversionService);
    binder.addValidators(validator);/*from  w w  w  . j  a  va2 s.com*/
    binder.bind(new MutablePropertyValues(val));
    binder.validate();
    BindingResult result = binder.getBindingResult();
    assertEquals(0, result.getErrorCount());
    assertNull(dto.getZipCode0());
    assertEquals("", dto.getZipCode1());
    assertEquals("1234567", dto.getZipCode2());
    assertNull(dto.getZipCode3());
    assertEquals("", dto.getZipCode4());
    assertEquals("123-4567", dto.getZipCode5());
}

From source file:cherry.foundation.validator.TelNoValidatorTest.java

@Test
public void testOK() {

    Map<String, String> val = new HashMap<>();
    val.put("telNo0", null);
    val.put("telNo1", "");
    val.put("telNo2", "01-234-5678");
    val.put("telNo3", "01-2345-6789");
    val.put("telNo4", "012-345-6789");
    val.put("telNo5", "0123-45-6789");
    val.put("telNo6", "01234-5-6789");
    val.put("telNo7", "090-1234-5678");
    val.put("telNo8", "0120-123-456");

    TestDto dto = new TestDto();

    WebDataBinder binder = new WebDataBinder(dto);
    binder.setConversionService(conversionService);
    binder.addValidators(validator);//from  w  w  w  .j a  v a2s .c om
    binder.bind(new MutablePropertyValues(val));
    binder.validate();
    BindingResult result = binder.getBindingResult();
    assertEquals(0, result.getErrorCount());
    assertNull(dto.getTelNo0());
    assertEquals("", dto.getTelNo1());
    assertEquals("01-234-5678", dto.getTelNo2());
    assertEquals("01-2345-6789", dto.getTelNo3());
    assertEquals("012-345-6789", dto.getTelNo4());
    assertEquals("0123-45-6789", dto.getTelNo5());
    assertEquals("01234-5-6789", dto.getTelNo6());
    assertEquals("090-1234-5678", dto.getTelNo7());
    assertEquals("0120-123-456", dto.getTelNo8());
}

From source file:org.wallride.web.controller.admin.user.UserDescribeController.java

@RequestMapping
public String describe(@PathVariable String language, @RequestParam long id, String query, Model model) {
    User user = userService.getUserById(id);
    if (user == null) {
        throw new HttpNotFoundException();
    }/*from   w ww  .  java2  s .c  o m*/

    MutablePropertyValues mpvs = new MutablePropertyValues(
            UriComponentsBuilder.newInstance().query(query).build().getQueryParams());
    for (Iterator<PropertyValue> i = mpvs.getPropertyValueList().iterator(); i.hasNext();) {
        PropertyValue pv = i.next();
        boolean hasValue = false;
        for (String value : (List<String>) pv.getValue()) {
            if (StringUtils.hasText(value)) {
                hasValue = true;
                break;
            }
        }
        if (!hasValue) {
            i.remove();
        }
    }
    BeanWrapperImpl beanWrapper = new BeanWrapperImpl(new UserSearchForm());
    beanWrapper.setConversionService(conversionService);
    beanWrapper.setPropertyValues(mpvs, true, true);
    UserSearchForm form = (UserSearchForm) beanWrapper.getWrappedInstance();
    List<Long> ids = userService.getUserIds(form.toUserSearchRequest());
    if (!CollectionUtils.isEmpty(ids)) {
        int index = ids.indexOf(user.getId());
        if (index < ids.size() - 1) {
            Long next = ids.get(index + 1);
            model.addAttribute("next", next);
        }
        if (index > 0) {
            Long prev = ids.get(index - 1);
            model.addAttribute("prev", prev);
        }
    }

    model.addAttribute("user", user);
    model.addAttribute("query", query);
    return "user/describe";
}

From source file:newcontroller.handler.impl.DefaultRequest.java

@Override
public <T> T params(Class<T> clazz) {
    T obj = BeanUtils.instantiate(clazz);
    WebDataBinder binder = new WebDataBinder(obj);
    binder.bind(new MutablePropertyValues(this.request.getParameterMap()));
    return obj;/*from w  w  w.j a v a  2s .  co  m*/
}

From source file:de.iew.web.controllers.IdentityController.java

@RequestMapping(value = "/loginerror.html")
public ModelAndView loginError(HttpServletRequest request) {
    LoginForm loginForm = createLoginForm();

    DataBinder binder = new DataBinder(loginForm);
    MutablePropertyValues mutablePropertyValues = new MutablePropertyValues(request.getParameterMap());
    binder.bind(mutablePropertyValues);/*  w w  w . ja v a 2s  .  c o m*/

    ModelAndView mav = new ModelAndView(this.viewScript);
    mav.addObject(this.loginFormModelKey, loginForm);
    mav.addObject("error", true);
    mav.addObject("loginErrorMessage", "errors.login.denied.message");

    // Hole den Login Fehler und verffentliche die Fehlermeldungen
    Exception e = (Exception) request.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
    if (e instanceof ValidatingFormAuthenticationFilter.LoginFormValidationException) {
        ValidatingFormAuthenticationFilter.LoginFormValidationException ex = (ValidatingFormAuthenticationFilter.LoginFormValidationException) e;
        BindingResult res = ex.getErrors();
        /*
        Oh man :-D
                
        @see http://stackoverflow.com/questions/6704478/access-spring-mvc-bindingresult-from-within-a-view
         */
        mav.addObject(BindingResult.MODEL_KEY_PREFIX + this.loginFormModelKey, res);
    }

    return mav;
}

From source file:cherry.foundation.validator.CharTypeValidatorTest.java

@Test
public void testOK() {

    Map<String, String> val = new HashMap<>();
    val.put("none", "");
    val.put("space", " \t\r\n");
    val.put("numeric", "0123456789");
    val.put("alpha", "ABCabc");
    val.put("upper", "ABC");
    val.put("lower", "abc");
    val.put("surrogate", "\uD842\uDF9F");

    TestDto dto = new TestDto();

    WebDataBinder binder = new WebDataBinder(dto);
    binder.setConversionService(conversionService);
    binder.addValidators(validator);/*  ww  w. ja va2  s . c  o  m*/
    binder.bind(new MutablePropertyValues(val));
    binder.validate();
    BindingResult result = binder.getBindingResult();
    assertThat(result.getErrorCount(), is(0));
    assertThat(dto.getSpace(), is(" \t\r\n"));
    assertThat(dto.getNumeric(), is("0123456789"));
    assertThat(dto.getAlpha(), is("ABCabc"));
    assertThat(dto.getUpper(), is("ABC"));
    assertThat(dto.getLower(), is("abc"));
    assertThat(dto.getSurrogate(), is("\uD842\uDF9F"));
}

From source file:org.terasoluna.gfw.web.el.ObjectToMapConverterTest.java

@Test
public void testConvert0_SimpleJavaBean() throws Exception {
    Map<String, String> map = converter.convert(new SearchUserForm0("yamada", 20));
    assertThat(map.size(), is(2));/*  w  ww . j  a va 2s .c om*/
    assertThat(map, hasEntry("name", "yamada"));
    assertThat(map, hasEntry("age", "20"));

    // check reverse conversion
    SearchUserForm0 form = new SearchUserForm0();
    WebDataBinder binder = new WebDataBinder(form);
    binder.bind(new MutablePropertyValues(map));
    assertThat(form.getName(), is("yamada"));
    assertThat(form.getAge(), is(20));
}