Example usage for org.springframework.validation BindingResult getErrorCount

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

Introduction

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

Prototype

int getErrorCount();

Source Link

Document

Return the total number of errors.

Usage

From source file:com.google.ie.dto.ViewStatus.java

/**
 * @param errors/*from w  w w. j  a  v a 2 s. c om*/
 */
public static ViewStatus createErrorViewStatus(BindingResult errors) {
    ViewStatus viewStatus = new ViewStatus();
    log.warn("Idea object has " + errors.getErrorCount() + " validation errors");
    viewStatus.setStatus(WebConstants.ERROR);
    for (Iterator<FieldError> iterator = errors.getFieldErrors().iterator(); iterator.hasNext();) {
        FieldError fieldError = iterator.next();
        viewStatus.addMessage(fieldError.getField(), fieldError.getDefaultMessage());
        log.warn("Error found in field: " + fieldError.getField() + " Message :"
                + fieldError.getDefaultMessage());
    }
    return viewStatus;

}

From source file:com.google.ie.dto.ViewStatus.java

/**
 * @param errors//  www  .j  ava  2 s . c om
 */
public static ViewStatus createProjectErrorViewStatus(BindingResult errors) {
    ViewStatus viewStatus = new ViewStatus();
    log.warn("Project object has " + errors.getErrorCount() + " validation errors");
    viewStatus.setStatus(WebConstants.ERROR);
    for (Iterator<ObjectError> iterator = errors.getAllErrors().iterator(); iterator.hasNext();) {
        ObjectError objError = iterator.next();
        if (objError instanceof FieldError) {
            FieldError fieldError = (FieldError) objError;
            viewStatus.addMessage(WebConstants.ERROR,
                    fieldError.getField() + " - " + fieldError.getDefaultMessage());
            log.warn("Error found in field: " + fieldError.getField() + " Message :"
                    + objError.getDefaultMessage());
        } else {
            viewStatus.addMessage(WebConstants.ERROR, objError.getDefaultMessage());
            log.warn(" Message :" + objError.getDefaultMessage());
        }

    }
    return viewStatus;

}

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

@Test
public void testNG() {

    Map<String, String> val = new HashMap<>();
    val.put("val3", "1234");
    val.put("val4", "123");

    TestDto dto = new TestDto();

    WebDataBinder binder = new WebDataBinder(dto);
    binder.setConversionService(conversionService);
    binder.addValidators(validator);//from w  ww .  ja v a2s. c  o m
    binder.bind(new MutablePropertyValues(val));
    binder.validate();
    BindingResult result = binder.getBindingResult();
    assertEquals(2, result.getErrorCount());
}

From source file:com.asual.summer.core.spring.ExtendedBindingErrorProcessor.java

public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) {
    super.processPropertyAccessException(ex, bindingResult);
    Object[] arguments = bindingResult.getAllErrors().get(bindingResult.getErrorCount() - 1).getArguments();
    arguments[1] = ExceptionUtils.getRootCause(ex).getMessage();
}

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);//  w  w  w  . ja v  a2 s  . c  om
    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 testNG() {

    Map<String, String> val = new HashMap<>();
    val.put("zipCode0", "123456");
    val.put("zipCode1", "12345678");
    val.put("zipCode2", "abcdefg");
    val.put("zipCode3", "123-456");
    val.put("zipCode4", "123-45678");
    val.put("zipCode5", "abc-defg");

    TestDto dto = new TestDto();

    WebDataBinder binder = new WebDataBinder(dto);
    binder.setConversionService(conversionService);
    binder.addValidators(validator);//w ww. j a v a  2  s  .c  o  m
    binder.bind(new MutablePropertyValues(val));
    binder.validate();
    BindingResult result = binder.getBindingResult();
    assertEquals(6, result.getErrorCount());
}

From source file:org.frat.common.validation.ValidateException.java

/**
 * // w w  w . j a va2s  .c  o  m
 * Description: TODO.
 * 
 * @param bindingResult
 * @return
 */
public int getErrorCount(final BindingResult bindingResult) {
    return bindingResult.getErrorCount();
}

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);/*  w ww  .  j a  v a 2  s.c  o  m*/
    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:br.edu.ifrs.restinga.modulorh.controle.SetorController.java

@RequestMapping(value = "/setor/salvarSetor", method = RequestMethod.POST)
public String salvarSetor(@Valid Setor setor, BindingResult result, ModelMap model) {

    if (result.getErrorCount() == 0) {
        setorDAO.cadastrar(setor);/* ww w . j  a v a2 s. com*/
        mensagem = "cadastro realizado com sucesso";
    } else {
        mensagem = "Erro";
    }

    model.addAttribute("mensagemTitulo", mensagem);
    return "forward:/setor";
}

From source file:br.edu.ifrs.restinga.modulorh.controle.SetorController.java

@RequestMapping("/setor/salvarEdicao")
public String salvarEdicao(@Valid Setor setor, BindingResult result, ModelMap model) {

    if (result.getErrorCount() == 0) {
        setorDAO.alterar(setor);/*w w w . j  ava 2 s.  c  om*/
        mensagem = "Setor editado com sucesso!";
    } else {
        mensagem = "Erro";
        return "forward:/setor";
    }

    model.addAttribute("mensagemTitulo", mensagem);
    return "redirect:/setor/listarSetor";

}