|
|
@ -26,6 +26,8 @@ import reactor.core.publisher.Mono; |
|
|
|
import reactor.core.publisher.Sinks; |
|
|
|
import reactor.core.publisher.Sinks; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
|
|
|
import org.springframework.context.i18n.LocaleContext; |
|
|
|
|
|
|
|
import org.springframework.context.i18n.LocaleContextHolder; |
|
|
|
import org.springframework.core.MethodParameter; |
|
|
|
import org.springframework.core.MethodParameter; |
|
|
|
import org.springframework.core.ReactiveAdapter; |
|
|
|
import org.springframework.core.ReactiveAdapter; |
|
|
|
import org.springframework.core.ReactiveAdapterRegistry; |
|
|
|
import org.springframework.core.ReactiveAdapterRegistry; |
|
|
@ -121,7 +123,7 @@ public class ModelAttributeMethodArgumentResolver extends HandlerMethodArgumentR |
|
|
|
return (bindingDisabled(parameter) ? Mono.empty() : bindRequestParameters(binder, exchange)) |
|
|
|
return (bindingDisabled(parameter) ? Mono.empty() : bindRequestParameters(binder, exchange)) |
|
|
|
.doOnError(bindingResultSink::tryEmitError) |
|
|
|
.doOnError(bindingResultSink::tryEmitError) |
|
|
|
.doOnSuccess(aVoid -> { |
|
|
|
.doOnSuccess(aVoid -> { |
|
|
|
validateIfApplicable(binder, parameter); |
|
|
|
validateIfApplicable(binder, parameter, exchange); |
|
|
|
BindingResult bindingResult = binder.getBindingResult(); |
|
|
|
BindingResult bindingResult = binder.getBindingResult(); |
|
|
|
model.put(BindingResult.MODEL_KEY_PREFIX + name, bindingResult); |
|
|
|
model.put(BindingResult.MODEL_KEY_PREFIX + name, bindingResult); |
|
|
|
model.put(name, value); |
|
|
|
model.put(name, value); |
|
|
@ -278,11 +280,23 @@ public class ModelAttributeMethodArgumentResolver extends HandlerMethodArgumentR |
|
|
|
return (paramTypes.length > i + 1 && Errors.class.isAssignableFrom(paramTypes[i + 1])); |
|
|
|
return (paramTypes.length > i + 1 && Errors.class.isAssignableFrom(paramTypes[i + 1])); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void validateIfApplicable(WebExchangeDataBinder binder, MethodParameter parameter) { |
|
|
|
private void validateIfApplicable(WebExchangeDataBinder binder, MethodParameter parameter, ServerWebExchange exchange) { |
|
|
|
for (Annotation ann : parameter.getParameterAnnotations()) { |
|
|
|
LocaleContext localeContext = null; |
|
|
|
Object[] validationHints = ValidationAnnotationUtils.determineValidationHints(ann); |
|
|
|
try { |
|
|
|
if (validationHints != null) { |
|
|
|
for (Annotation ann : parameter.getParameterAnnotations()) { |
|
|
|
binder.validate(validationHints); |
|
|
|
Object[] validationHints = ValidationAnnotationUtils.determineValidationHints(ann); |
|
|
|
|
|
|
|
if (validationHints != null) { |
|
|
|
|
|
|
|
if (localeContext == null) { |
|
|
|
|
|
|
|
localeContext = exchange.getLocaleContext(); |
|
|
|
|
|
|
|
LocaleContextHolder.setLocaleContext(localeContext); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
binder.validate(validationHints); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
finally { |
|
|
|
|
|
|
|
if (localeContext != null) { |
|
|
|
|
|
|
|
LocaleContextHolder.resetLocaleContext(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|