Polishing

This commit is contained in:
Juergen Hoeller
2018-08-02 17:45:46 +02:00
parent 2474c48749
commit 217aa38cbb
2 changed files with 13 additions and 11 deletions

View File

@@ -53,11 +53,13 @@ public class InitBinderDataBinderFactory extends DefaultDataBinderFactory {
this.binderMethods = (binderMethods != null ? binderMethods : Collections.emptyList());
}
/**
* Initialize a WebDataBinder with {@code @InitBinder} methods.
* <p>If the {@code @InitBinder} annotation specifies attributes names,
* it is invoked only if the names include the target object name.
* @throws Exception if one of the invoked @{@link InitBinder} methods fail.
* @throws Exception if one of the invoked @{@link InitBinder} methods fails
* @see #isBinderMethodApplicable
*/
@Override
public void initBinder(WebDataBinder dataBinder, NativeWebRequest request) throws Exception {
@@ -66,19 +68,19 @@ public class InitBinderDataBinderFactory extends DefaultDataBinderFactory {
Object returnValue = binderMethod.invokeForRequest(request, null, dataBinder);
if (returnValue != null) {
throw new IllegalStateException(
"@InitBinder methods should return void: " + binderMethod);
"@InitBinder methods must not return a value (should be void): " + binderMethod);
}
}
}
}
/**
* Whether the given {@code @InitBinder} method should be used to initialize
* the given WebDataBinder instance. By default we check the attributes
* names of the annotation, if present.
* Determine whether the given {@code @InitBinder} method should be used
* to initialize the given {@link WebDataBinder} instance. By default we
* check the specified attribute names in the annotation value, if any.
*/
protected boolean isBinderMethodApplicable(HandlerMethod binderMethod, WebDataBinder dataBinder) {
InitBinder ann = binderMethod.getMethodAnnotation(InitBinder.class);
protected boolean isBinderMethodApplicable(HandlerMethod initBinderMethod, WebDataBinder dataBinder) {
InitBinder ann = initBinderMethod.getMethodAnnotation(InitBinder.class);
Assert.state(ann != null, "No InitBinder annotation");
String[] names = ann.value();
return (ObjectUtils.isEmpty(names) || ObjectUtils.containsElement(names, dataBinder.getObjectName()));

View File

@@ -83,18 +83,18 @@ class InitBinderBindingContext extends BindingContext {
return dataBinder;
}
private void invokeBinderMethod(WebExchangeDataBinder dataBinder, ServerWebExchange exchange,
SyncInvocableHandlerMethod binderMethod) {
private void invokeBinderMethod(
WebExchangeDataBinder dataBinder, ServerWebExchange exchange, SyncInvocableHandlerMethod binderMethod) {
HandlerResult result = binderMethod.invokeForHandlerResult(exchange, this.binderMethodContext, dataBinder);
if (result != null && result.getReturnValue() != null) {
throw new IllegalStateException(
"@InitBinder methods should return void: " + binderMethod);
"@InitBinder methods must not return a value (should be void): " + binderMethod);
}
// Should not happen (no Model argument resolution) ...
if (!this.binderMethodContext.getModel().asMap().isEmpty()) {
throw new IllegalStateException(
"@InitBinder methods should not add model attributes: " + binderMethod);
"@InitBinder methods are not allowed to add model attributes: " + binderMethod);
}
}