Examples of FieldError


Examples of org.apache.struts2.components.FieldError

    protected String fieldName;


    public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
        return new FieldError(stack, req, res);
    }
View Full Code Here

Examples of org.apache.struts2.components.FieldError

    }

    protected void populateParams() {
        super.populateParams();

        FieldError fieldError = ((FieldError) component);
        fieldError.setFieldName(this.fieldName);
    }
View Full Code Here

Examples of org.springframework.validation.FieldError

            Field f = clazz.getDeclaredField(field);
            Object value = this.getValueObject(f.getType(), fieldValue);
            f.setAccessible(true);
            f.set(formBackingObject, value);
            Errors errors = validateObject(formBackingObject);
            FieldError error = errors.getFieldError(field);
            if (error != null) message = error.getCode();
        }
        return message;
    }
View Full Code Here

Examples of org.springframework.validation.FieldError

            Field f = clazz.getDeclaredField(field);
            Object value = this.getValueObject(f.getType(), fieldValue);
            f.setAccessible(true);
            f.set(formBackingObject, value);
            Errors errors = validateObject(formBackingObject);
            FieldError error = errors.getFieldError(field);
            if (error != null) message = error.getCode();
        }
        return message;
    }
View Full Code Here

Examples of org.springframework.validation.FieldError

    public <T> T visit(Object element) {
        try {
            return super.<T>visit(element);
        } catch (IllegalArgumentException ia) {
            if (FieldError.class.isAssignableFrom(element.getClass())) {
                FieldError e = (FieldError) element;
                FieldError t = new FieldError(e.getObjectName(), e.getField(), e.getRejectedValue(), false, e.getCodes(), null, this.visit(e.getCode()));
                return (T) t;
            } else {
                throw ia;
            }
        }
View Full Code Here

Examples of org.springframework.validation.FieldError

        assertEquals(ERROR_MESSAGE_EMPTY_TODO_TITLE, titleFieldErrorDTO.getMessage());
    }

    @Test
    public void handleFormValidationErrorWhenErrorMessagesAreNotFound() {
        FieldError titleError = createFieldError(OBJECT_NAME, FIELD_TITLE, ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE);
        FieldError descriptionError = createFieldError(OBJECT_NAME, FIELD_DESCRIPTION, ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION);

        List<FieldError> errors = new ArrayList<FieldError>();
        errors.add(titleError);
        errors.add(descriptionError);

        FormValidationError validationError = new FormValidationError(errors);

        when(localeHolderWrapperMock.getCurrentLocale()).thenReturn(Locale.US);

        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US)).thenReturn(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE);
        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION, descriptionError.getArguments(), Locale.US)).thenReturn(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION);

        FormValidationErrorDTO dto = controller.handleFormValidationError(validationError);

        verify(localeHolderWrapperMock, times(1)).getCurrentLocale();
        verifyNoMoreInteractions(localeHolderWrapperMock);

        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US);
        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION, descriptionError.getArguments(), Locale.US);
        verifyNoMoreInteractions(messageSourceMock);

        verifyZeroInteractions(serviceMock);

        List<FieldValidationErrorDTO> fieldErrorDTOs = dto.getFieldErrors();
View Full Code Here

Examples of org.springframework.validation.FieldError

        assertEquals(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION, descriptionFieldErrorDTO.getMessage());
    }

    @Test
    public void handleFormValidationErrorWhenErrorMessagesAreNull() {
        FieldError titleError = createFieldError(OBJECT_NAME, FIELD_TITLE, ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE);
        FieldError descriptionError = createFieldError(OBJECT_NAME, FIELD_DESCRIPTION, ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION);

        List<FieldError> errors = new ArrayList<FieldError>();
        errors.add(titleError);
        errors.add(descriptionError);

        FormValidationError validationError = new FormValidationError(errors);

        when(localeHolderWrapperMock.getCurrentLocale()).thenReturn(Locale.US);

        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US)).thenReturn(null);
        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION, descriptionError.getArguments(), Locale.US)).thenReturn(null);

        FormValidationErrorDTO dto = controller.handleFormValidationError(validationError);

        verify(localeHolderWrapperMock, times(1)).getCurrentLocale();
        verifyNoMoreInteractions(localeHolderWrapperMock);

        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US);
        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION, descriptionError.getArguments(), Locale.US);
        verifyNoMoreInteractions(messageSourceMock);

        verifyZeroInteractions(serviceMock);

        List<FieldValidationErrorDTO> fieldErrorDTOs = dto.getFieldErrors();
View Full Code Here

Examples of org.springframework.validation.FieldError

        assertEquals(expected.getDescription(), actual.getDescription());
        assertEquals(expected.getTitle(), actual.getTitle());
    }

    public FieldError createFieldError(String objectName, String path, String... errorMessageCodes) {
        return new FieldError(objectName,
                path,
                null,
                false,
                errorMessageCodes,
                new Object[]{},
View Full Code Here

Examples of org.springframework.validation.FieldError

        verifyZeroInteractions(localeHolderWrapperMock, messageSourceMock);
    }

    @Test
    public void handleFormValidationError() {
        FieldError titleError = createFieldError(OBJECT_NAME, FIELD_TITLE, ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE);
        FieldError descriptionError = createFieldError(OBJECT_NAME, FIELD_DESCRIPTION, ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION);

        List<FieldError> errors = new ArrayList<FieldError>();
        errors.add(titleError);
        errors.add(descriptionError);

        FormValidationError validationError = new FormValidationError(errors);

        when(localeHolderWrapperMock.getCurrentLocale()).thenReturn(Locale.US);

        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US)).thenReturn(ERROR_MESSAGE_EMPTY_TODO_TITLE);
        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION, descriptionError.getArguments(), Locale.US)).thenReturn(ERROR_MESSAGE_TOO_LONG_DESCRIPTION);

        FormValidationErrorDTO dto = controller.handleFormValidationError(validationError);

        verify(localeHolderWrapperMock, times(1)).getCurrentLocale();
        verifyNoMoreInteractions(localeHolderWrapperMock);

        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US);
        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_TOO_LONG_DESCRIPTION, descriptionError.getArguments(), Locale.US);
        verifyNoMoreInteractions(messageSourceMock);

        verifyZeroInteractions(serviceMock);

        List<FieldValidationErrorDTO> fieldErrorDTOs = dto.getFieldErrors();
View Full Code Here

Examples of org.springframework.validation.FieldError

        assertEquals(ERROR_MESSAGE_TOO_LONG_DESCRIPTION, descriptionFieldErrorDTO.getMessage());
    }

    @Test
    public void handleFormValidationErrorWhenErrorMessageIsNotFoundWithFirstErrorCode() {
        FieldError titleError = createFieldError(OBJECT_NAME, FIELD_TITLE, ERROR_MESSAGE_CODE_EMPTY_TITLE, ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE);

        List<FieldError> errors = new ArrayList<FieldError>();
        errors.add(titleError);

        FormValidationError validationError = new FormValidationError(errors);

        when(localeHolderWrapperMock.getCurrentLocale()).thenReturn(Locale.US);

        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_EMPTY_TITLE, titleError.getArguments(), Locale.US)).thenReturn(ERROR_MESSAGE_CODE_EMPTY_TITLE);
        when(messageSourceMock.getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US)).thenReturn(ERROR_MESSAGE_EMPTY_TODO_TITLE);

        FormValidationErrorDTO dto = controller.handleFormValidationError(validationError);

        verify(localeHolderWrapperMock, times(1)).getCurrentLocale();
        verifyNoMoreInteractions(localeHolderWrapperMock);

        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_EMPTY_TITLE, titleError.getArguments(), Locale.US);
        verify(messageSourceMock, times(1)).getMessage(ERROR_MESSAGE_CODE_EMPTY_TODO_TITLE, titleError.getArguments(), Locale.US);
        verifyNoMoreInteractions(messageSourceMock);

        verifyZeroInteractions(serviceMock);

        List<FieldValidationErrorDTO> fieldErrorDTOs = dto.getFieldErrors();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.