Package org.springframework.web.bind

Examples of org.springframework.web.bind.ServletRequestParameterPropertyValues


                    WebDataBinder componentBinder = binderFactory.createBinder(request, component, null);
                    component = componentBinder.getTarget();

                    if (component != null) {
                        ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(servletRequest, prefixName, "");
                        componentBinder.bind(pvs);
                        validateIfApplicable(componentBinder, parameter);
                        if (componentBinder.getBindingResult().hasErrors()) {
                            if (isBindExceptionRequired(componentBinder, parameter)) {
                                throw new BindException(componentBinder.getBindingResult());
                            }
                        }
                        targetList.set(index, component);
                    }
                }
                target.clear();
                target.addAll(targetList);
            }
        } else if (MapWapper.class.isAssignableFrom(targetType)) {


            Type type = parameter.getGenericParameterType();
            Class<?> keyType = Object.class;
            Class<?> valueType = Object.class;

            if (type instanceof ParameterizedType) {
                keyType = (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[0];
                valueType = (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[1];
            }


            MapWapper mapWapper = ((MapWapper) binder.getTarget());
            Map target = mapWapper.getInnerMap();
            if(target == null) {
                target = new HashMap();
                mapWapper.setInnerMap(target);
            }

            for (Object key : servletRequest.getParameterMap().keySet()) {
                String prefixName = getPrefixName((String) key);

                //每个prefix 只处理一次
                if (hasProcessedPrefixMap.containsKey(prefixName)) {
                    continue;
                } else {
                    hasProcessedPrefixMap.put(prefixName, Boolean.TRUE);
                }

                Object keyValue = simpleBinder.convertIfNecessary(getMapKey(prefixName), keyType);

                if (isSimpleComponent(prefixName)) { //bind simple type
                    Map<String, Object> paramValues = WebUtils.getParametersStartingWith(servletRequest, prefixName);

                    for (Object value : paramValues.values()) {
                        target.put(keyValue, simpleBinder.convertIfNecessary(value, valueType));
                    }
                } else {

                    Object component = target.get(keyValue);
                    if(component == null) {
                        component = BeanUtils.instantiate(valueType);
                    }

                    WebDataBinder componentBinder = binderFactory.createBinder(request, component, null);
                    component = componentBinder.getTarget();

                    if (component != null) {
                        ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(servletRequest, prefixName, "");
                        componentBinder.bind(pvs);

                        validateComponent(componentBinder, parameter);

                        target.put(keyValue, component);
View Full Code Here


    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("forname", "Tony");
    request.addParameter("surname", "Blair");
    request.addParameter("age", "" + 50);

    ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
    doTestTony(pvs);
  }
View Full Code Here

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("test_forname", "Tony");
    request.addParameter("test_surname", "Blair");
    request.addParameter("test_age", "" + 50);

    ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
    assertTrue("Didn't fidn normal when given prefix", !pvs.contains("forname"));
    assertTrue("Did treat prefix as normal when not given prefix", pvs.contains("test_forname"));

    pvs = new ServletRequestParameterPropertyValues(request, "test");
    doTestTony(pvs);
  }
View Full Code Here

  }

  @Test
  public void testNoParameters() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
    assertTrue("Found no parameters", pvs.getPropertyValues().length == 0);
  }
View Full Code Here

  public void testMultipleValuesForParameter() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    String[] original = new String[] {"Tony", "Rod"};
    request.addParameter("forname", original);

    ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(request);
    assertTrue("Found 1 parameter", pvs.getPropertyValues().length == 1);
    assertTrue("Found array value", pvs.getPropertyValue("forname").getValue() instanceof String[]);
    String[] values = (String[]) pvs.getPropertyValue("forname").getValue();
    assertEquals("Correct values", Arrays.asList(values), Arrays.asList(original));
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.bind.ServletRequestParameterPropertyValues

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.