polish
This commit is contained in:
@@ -21,6 +21,7 @@ import org.springframework.ui.binding.BindingResults;
|
|||||||
import org.springframework.ui.binding.UserValues;
|
import org.springframework.ui.binding.UserValues;
|
||||||
import org.springframework.ui.binding.support.WebBinder;
|
import org.springframework.ui.binding.support.WebBinder;
|
||||||
import org.springframework.ui.message.MessageContext;
|
import org.springframework.ui.message.MessageContext;
|
||||||
|
import org.springframework.ui.validation.ValidateResults;
|
||||||
import org.springframework.ui.validation.Validator;
|
import org.springframework.ui.validation.Validator;
|
||||||
|
|
||||||
public class WebBindAndValidateLifecycle {
|
public class WebBindAndValidateLifecycle {
|
||||||
@@ -40,10 +41,11 @@ public class WebBindAndValidateLifecycle {
|
|||||||
|
|
||||||
public void execute(Map<String, ? extends Object> userMap) {
|
public void execute(Map<String, ? extends Object> userMap) {
|
||||||
UserValues values = binder.createUserValues(userMap);
|
UserValues values = binder.createUserValues(userMap);
|
||||||
BindingResults results = binder.bind(values);
|
BindingResults bindingResults = binder.bind(values);
|
||||||
if (validationDecider.shouldValidateAfter(results)) {
|
if (validationDecider.shouldValidateAfter(bindingResults)) {
|
||||||
validator.validate(binder.getModel(), results.successes().properties());
|
ValidateResults validationResults = validator.validate(binder.getModel(), bindingResults.successes().properties());
|
||||||
}
|
}
|
||||||
|
// TODO translate binding and validation results into messages
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ValidationDecider {
|
public interface ValidationDecider {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public interface BindingResults extends Iterable<BindingResult> {
|
|||||||
BindingResult get(int index);
|
BindingResult get(int index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of properties for which binding was attempted.
|
* The ordered list of properties for which a {@link BindingResult} was returned.
|
||||||
*/
|
*/
|
||||||
List<String> properties();
|
List<String> properties();
|
||||||
|
|
||||||
|
|||||||
@@ -197,6 +197,7 @@ public class GenericBinder implements Binder {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class BindingImpl implements Binding {
|
class BindingImpl implements Binding {
|
||||||
|
|
||||||
private Expression property;
|
private Expression property;
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import org.springframework.ui.format.number.IntegerFormatter;
|
|||||||
public class GenericBinderTests {
|
public class GenericBinderTests {
|
||||||
|
|
||||||
private TestBean bean;
|
private TestBean bean;
|
||||||
|
|
||||||
private Binder binder;
|
private Binder binder;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package org.springframework.ui.validation;
|
||||||
|
|
||||||
|
public interface ValidateResults {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,6 +4,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface Validator {
|
public interface Validator {
|
||||||
|
|
||||||
void validate(Object model, List<String> properties);
|
ValidateResults validate(Object model, List<String> properties);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user