Example usage for org.springframework.validation BindingResult MODEL_KEY_PREFIX

List of usage examples for org.springframework.validation BindingResult MODEL_KEY_PREFIX

Introduction

In this page you can find the example usage for org.springframework.validation BindingResult MODEL_KEY_PREFIX.

Prototype

String MODEL_KEY_PREFIX

To view the source code for org.springframework.validation BindingResult MODEL_KEY_PREFIX.

Click Source Link

Document

Prefix for the name of the BindingResult instance in a model, followed by the object name.

Usage

From source file:com.sinosoft.one.mvc.web.impl.thread.InvocationBean.java

public BindingResult getParameterBindingResult() {
    return (BindingResult) this.getModel()
            .get(BindingResult.MODEL_KEY_PREFIX + ParameterBindingResult.OBJECT_NAME);
}

From source file:com.sinosoft.one.mvc.web.impl.thread.InvocationBean.java

public BindingResult getBindingResult(String name) {
    Assert.notNull(name);//from ww w  .  j a v  a  2s.  co m
    if (name instanceof String) {
        if (!((String) name).endsWith("BindingResult")) {
            name = name + "BindingResult";
        }
        BindingResult br = (BindingResult) this.getModel().get(BindingResult.MODEL_KEY_PREFIX + name);
        if (br == null) {
            br = getParameterBindingResult();
        }
        return br;
    }
    return null;
}

From source file:com.laxser.blitz.web.impl.thread.InvocationBean.java

@Override
public BindingResult getParameterBindingResult() {
    return (BindingResult) this.getModel()
            .get(BindingResult.MODEL_KEY_PREFIX + ParameterBindingResult.OBJECT_NAME);
}

From source file:com.laxser.blitz.web.impl.thread.InvocationBean.java

@Override
public BindingResult getBindingResult(String name) {
    Assert.notNull(name);//from w w w. j  av  a2  s  . c  o  m
    if (name instanceof String) {
        if (!((String) name).endsWith("BindingResult")) {
            name = name + "BindingResult";
        }
        BindingResult br = (BindingResult) this.getModel().get(BindingResult.MODEL_KEY_PREFIX + name);
        if (br == null) {
            br = getParameterBindingResult();
        }
        return br;
    }
    return null;
}

From source file:com.laxser.blitz.web.impl.thread.InvocationBean.java

protected void fetchBindingResults() {
    if (this.bindingResults == null) {
        Map<String, Object> attributes = getModel().getAttributes();
        List<String> bindingResultNames = new ArrayList<String>();
        List<BindingResult> bindingResults = new ArrayList<BindingResult>();
        for (String key : attributes.keySet()) {
            if (key.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
                Object value = attributes.get(key);
                if (value instanceof BindingResult) {
                    bindingResults.add((BindingResult) value);
                    bindingResultNames.add(((BindingResult) value).getObjectName());
                }/*from  www  .ja  v  a 2 s  .  co  m*/
            }
        }
        this.bindingResults = Collections.unmodifiableList(bindingResults);
        this.bindingResultNames = Collections.unmodifiableList(bindingResultNames);
    }
}

From source file:eu.delving.services.controller.DataSetController.java

private ModelAndView view(MetaRepo.DataSet dataSet) throws DataSetNotFoundException {
    if (dataSet == null) {
        throw new DataSetNotFoundException("Data Set was null");
    }/* w  w  w  .  j  a  v a  2s . com*/
    DataSetResponse response = new DataSetResponse(DataSetResponseCode.THANK_YOU);
    response.addDataSetInfo(getInfo(dataSet));
    return new ModelAndView("dataSetXmlView", BindingResult.MODEL_KEY_PREFIX + "response", response);
}

From source file:eu.delving.services.controller.DataSetController.java

private ModelAndView view(DataSetResponse response) {
    return new ModelAndView("dataSetXmlView", BindingResult.MODEL_KEY_PREFIX + "response", response);
}

From source file:org.hdiv.webflow.mvc.servlet.ServletMvcViewHDIV.java

private void exposeBindingModel(Map model) {
    Object modelObject = getModelObject();
    if (modelObject != null) {
        BindingModel bindingModel = new BindingModel(getModelExpression().getExpressionString(), modelObject,
                expressionParser, conversionService, requestContext.getMessageContext());
        bindingModel.setBinderConfiguration(binderConfiguration);
        bindingModel.setMappingResults(mappingResults);
        model.put(BindingResult.MODEL_KEY_PREFIX + getModelExpression().getExpressionString(), bindingModel);
    }//from  ww w . j  ava  2s .c o m
}

From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.TestSharedBuildNumberController.java

@Test
public void testDoHandleAddBuildNumberPost01() throws IOException, ServletException {
    this.setUpSecurity();

    expect(this.request.getParameter("action")).andReturn("add");
    expect(this.request.getMethod()).andReturn("POST");
    expect(this.request.getParameter("name")).andReturn("help");
    expect(this.request.getParameter("description")).andReturn("");
    expect(this.request.getParameter("format")).andReturn("{0");
    expect(this.request.getParameter("dateFormat")).andReturn("Ym");
    expect(this.request.getParameter("counter")).andReturn("15.1");

    replay(this.service, this.request, this.response);

    ModelAndView modelAndView = this.controller.doHandle(this.request, this.response);

    assertNotNull("The model and view should not be null.", modelAndView);
    assertEquals("The view is not correct.", "/plugin/" + testNum + "/jsp/addBuildNumber.jsp",
            modelAndView.getViewName());

    Map<String, Object> model = modelAndView.getModel();
    assertNotNull("The model should not be null.", model);

    Object object = model.get(BindingResult.MODEL_KEY_PREFIX + "sharedBuildNumberForm");
    assertNotNull("The binding result attribute should not be null.", object);
    assertTrue("The binding result attribute should be a binding result object.",
            object instanceof BindingResult);

    BindingResult result = (BindingResult) object;
    assertEquals("The binding result object name is not correct.", "sharedBuildNumberForm",
            result.getObjectName());/*from ww w  . j  av a2 s .  c  o m*/
    assertTrue("The binding result should have errors.", result.hasErrors());
    assertEquals("The binding result should have 3 errors.", 3, result.getErrorCount());

    List<FieldError> errors = result.getFieldErrors();
    assertNotNull("The list of errors should not be null.", errors);
    assertEquals("The list length is not correct.", 3, errors.size());
    assertEquals("The first error is not correct.", "counter", errors.get(0).getField());
    assertEquals("The first error has the wrong message.", "The counter must be a positive integer.",
            errors.get(0).getDefaultMessage());
    assertEquals("The second error is not correct.", "name", errors.get(1).getField());
    assertEquals("The second error has the wrong message.",
            "The name must be between 5 and 60 characters long.", errors.get(1).getDefaultMessage());
    assertEquals("The third error is not correct.", "format", errors.get(2).getField());
    assertEquals("The third error has the wrong message.",
            "The build number format must be at least 3 characters long.", errors.get(2).getDefaultMessage());

    object = model.get("sharedBuildNumberForm");
    assertNotNull("sharedBuildNumberForm should not be null.", object);
    assertTrue("sharedBuildNumberForm should be a SharedBuildNumber.", object instanceof SharedBuildNumber);

    SharedBuildNumber form = (SharedBuildNumber) object;
    assertEquals("The name is not correct.", "help", form.getName());
    assertEquals("The description is not correct.", "", form.getDescription());
    assertEquals("The format is not correct.", "{0", form.getFormat());
    assertEquals("The date format is not correct.", "Ym", form.getDateFormat());
    assertEquals("The counter is not correct.", 1, form.getCounter());
}

From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.TestSharedBuildNumberController.java

@Test
public void testDoHandleAddBuildNumberPost02() throws IOException, ServletException {
    this.setUpSecurity();

    expect(this.request.getParameter("action")).andReturn("add");
    expect(this.request.getMethod()).andReturn("POST");
    expect(this.request.getParameter("name")).andReturn("Hello");
    expect(this.request.getParameter("description")).andReturn("This is a description.");
    expect(this.request.getParameter("format")).andReturn("1.0.0.{D}");
    expect(this.request.getParameter("dateFormat")).andReturn("Ym");
    expect(this.request.getParameter("counter")).andReturn("-16");

    replay(this.service, this.request, this.response);

    ModelAndView modelAndView = this.controller.doHandle(this.request, this.response);

    assertNotNull("The model and view should not be null.", modelAndView);
    assertEquals("The view is not correct.", "/plugin/" + testNum + "/jsp/addBuildNumber.jsp",
            modelAndView.getViewName());

    Map<String, Object> model = modelAndView.getModel();
    assertNotNull("The model should not be null.", model);

    Object object = model.get(BindingResult.MODEL_KEY_PREFIX + "sharedBuildNumberForm");
    assertNotNull("The binding result attribute should not be null.", object);
    assertTrue("The binding result attribute should be a binding result object.",
            object instanceof BindingResult);

    BindingResult result = (BindingResult) object;
    assertEquals("The binding result object name is not correct.", "sharedBuildNumberForm",
            result.getObjectName());/* w w  w. j  a  va  2  s . com*/
    assertTrue("The binding result should have errors.", result.hasErrors());
    assertEquals("The binding result should have 2 errors.", 2, result.getErrorCount());

    List<FieldError> errors = result.getFieldErrors();
    assertNotNull("The list of errors should not be null.", errors);
    assertEquals("The list length is not correct.", 2, errors.size());
    assertEquals("The first error is not correct.", "counter", errors.get(0).getField());
    assertEquals("The first error has the wrong message.", "The counter must be a positive integer.",
            errors.get(0).getDefaultMessage());
    assertEquals("The second error is not correct.", "dateFormat", errors.get(1).getField());
    assertEquals("The second error has the wrong message.",
            "The date format must be at least 3 characters long.", errors.get(1).getDefaultMessage());

    object = model.get("sharedBuildNumberForm");
    assertNotNull("sharedBuildNumberForm should not be null.", object);
    assertTrue("sharedBuildNumberForm should be a SharedBuildNumber.", object instanceof SharedBuildNumber);

    SharedBuildNumber form = (SharedBuildNumber) object;
    assertEquals("The name is not correct.", "Hello", form.getName());
    assertEquals("The description is not correct.", "This is a description.", form.getDescription());
    assertEquals("The format is not correct.", "1.0.0.{D}", form.getFormat());
    assertEquals("The date format is not correct.", "Ym", form.getDateFormat());
    assertEquals("The counter is not correct.", 1, form.getCounter());
}