Example usage for org.springframework.validation Errors getFieldError

List of usage examples for org.springframework.validation Errors getFieldError

Introduction

In this page you can find the example usage for org.springframework.validation Errors getFieldError.

Prototype

@Nullable
FieldError getFieldError();

Source Link

Document

Get the first error associated with a field, if any.

Usage

From source file:com.rockagen.gnext.controller.ApplicationController.java

/**
 * Handle errors/*ww w.  j a va  2 s . com*/
 *
 * @param errors
 * @return
 */
public ErrorMsg error(Errors errors) {
    FieldError e = errors.getFieldError();
    ErrorMsg em = new ErrorMsg();
    em.field = e.getField();
    em.message = e.getDefaultMessage();
    em.value = e.getRejectedValue();
    return em;

}

From source file:InventoryServiceTest.java

@Test
public void assetValidatorDraftInvoice() throws Exception {
    Asset asset = inventoryService.getAssetsBySerialNumber("001").get(0);
    Invoice invoice = inventoryService.getLastInvoiceForAsset(asset);
    invoice.setStatus(Invoice.Status.DRAFT);
    inventoryService.save(invoice);// w  w  w  . jav  a2s .  co  m
    Errors errors = new BeanPropertyBindingResult(asset, "");
    assetValidator.validate(asset, errors);
    assertEquals(errors.getFieldError().getField(), 1, errors.getErrorCount());
    System.out.println(errors.getFieldError().getField());
}