Java Code Examples for org.springframework.validation.FieldError#getCode()
The following examples show how to use
org.springframework.validation.FieldError#getCode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelResultMatchers.java From spring-analysis-note with MIT License | 6 votes |
/** * Assert a field error code for a model attribute using a {@link org.hamcrest.Matcher}. * @since 4.1 */ public <T> ResultMatcher attributeHasFieldErrorCode(final String name, final String fieldName, final Matcher<? super String> matcher) { return mvcResult -> { ModelAndView mav = getModelAndView(mvcResult); BindingResult result = getBindingResult(mav, name); assertTrue("No errors for attribute: [" + name + "]", result.hasErrors()); FieldError fieldError = result.getFieldError(fieldName); if (fieldError == null) { fail("No errors for field '" + fieldName + "' of attribute '" + name + "'"); } String code = fieldError.getCode(); assertThat("Field name '" + fieldName + "' of attribute '" + name + "'", code, matcher); }; }
Example 2
Source File: ModelResultMatchers.java From java-technology-stack with MIT License | 6 votes |
/** * Assert a field error code for a model attribute using a {@link org.hamcrest.Matcher}. * @since 4.1 */ public <T> ResultMatcher attributeHasFieldErrorCode(final String name, final String fieldName, final Matcher<? super String> matcher) { return mvcResult -> { ModelAndView mav = getModelAndView(mvcResult); BindingResult result = getBindingResult(mav, name); assertTrue("No errors for attribute: [" + name + "]", result.hasErrors()); FieldError fieldError = result.getFieldError(fieldName); if (fieldError == null) { fail("No errors for field '" + fieldName + "' of attribute '" + name + "'"); } String code = fieldError.getCode(); assertThat("Field name '" + fieldName + "' of attribute '" + name + "'", code, matcher); }; }
Example 3
Source File: ModelResultMatchers.java From spring-analysis-note with MIT License | 5 votes |
/** * Assert a field error code for a model attribute using exact String match. * @since 4.1 */ public ResultMatcher attributeHasFieldErrorCode(final String name, final String fieldName, final String error) { return mvcResult -> { ModelAndView mav = getModelAndView(mvcResult); BindingResult result = getBindingResult(mav, name); assertTrue("No errors for attribute '" + name + "'", result.hasErrors()); FieldError fieldError = result.getFieldError(fieldName); if (fieldError == null) { fail("No errors for field '" + fieldName + "' of attribute '" + name + "'"); } String code = fieldError.getCode(); assertTrue("Expected error code '" + error + "' but got '" + code + "'", error.equals(code)); }; }
Example 4
Source File: ModelResultMatchers.java From java-technology-stack with MIT License | 5 votes |
/** * Assert a field error code for a model attribute using exact String match. * @since 4.1 */ public ResultMatcher attributeHasFieldErrorCode(final String name, final String fieldName, final String error) { return mvcResult -> { ModelAndView mav = getModelAndView(mvcResult); BindingResult result = getBindingResult(mav, name); assertTrue("No errors for attribute '" + name + "'", result.hasErrors()); FieldError fieldError = result.getFieldError(fieldName); if (fieldError == null) { fail("No errors for field '" + fieldName + "' of attribute '" + name + "'"); } String code = fieldError.getCode(); assertTrue("Expected error code '" + error + "' but got '" + code + "'", error.equals(code)); }; }
Example 5
Source File: FormErrorRepresentation.java From abixen-platform with GNU Lesser General Public License v2.1 | 4 votes |
public FormErrorRepresentation(FieldError fieldError) { this.field = fieldError.getField(); this.code = fieldError.getCode(); this.message = fieldError.getDefaultMessage(); this.rejectedValue = fieldError.getRejectedValue(); }
Example 6
Source File: ValidationResult.java From alf.io with GNU General Public License v3.0 | 4 votes |
public static ErrorDescriptor fromFieldError(FieldError fieldError) { return new ErrorDescriptor(fieldError.getField(), "", fieldError.getCode(), fieldError.getArguments()); }