提交 0096930a 编写于 作者: S Sam Brannen

Moving Validator and ValidateResults from src/test to src/main so that the...

Moving Validator and ValidateResults from src/test to src/main so that the build is no longer broken.
上级 9a84ef46
/*
* Copyright 2004-2009 the original author or authors.
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -24,35 +24,47 @@ import org.springframework.ui.message.MessageContext;
import org.springframework.ui.validation.ValidateResults;
import org.springframework.ui.validation.Validator;
/**
* TODO Document WebBindAndValidateLifecycle.
*
* @author Keith Donald
* @since 3.0
*/
public class WebBindAndValidateLifecycle {
private WebBinder binder;
@SuppressWarnings("unused")
private MessageContext messages;
private final WebBinder binder;
private final MessageContext messageContext;
private ValidationDecider validationDecider = ValidationDecider.ALWAYS_VALIDATE;
private Validator validator;
public WebBindAndValidateLifecycle(Object model, MessageContext messages) {
private Validator validator = null;
public WebBindAndValidateLifecycle(Object model, MessageContext messageContext) {
this.binder = new WebBinder(model);
this.messageContext = messageContext;
}
/**
* TODO Document execute().
*
* @param userMap
*/
public void execute(Map<String, ? extends Object> userMap) {
UserValues values = binder.createUserValues(userMap);
BindingResults bindingResults = binder.bind(values);
if (validationDecider.shouldValidateAfter(bindingResults)) {
ValidateResults validationResults = validator.validate(binder.getModel(), bindingResults.successes().properties());
ValidateResults validationResults = validator.validate(binder.getModel(), bindingResults.successes()
.properties());
}
// TODO translate binding and validation results into messages
}
public interface ValidationDecider {
interface ValidationDecider {
boolean shouldValidateAfter(BindingResults results);
public static ValidationDecider ALWAYS_VALIDATE = new ValidationDecider() {
static final ValidationDecider ALWAYS_VALIDATE = new ValidationDecider() {
public boolean shouldValidateAfter(BindingResults results) {
return true;
}
......
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ui.validation;
/**
* TODO Document ValidateResults.
*
* @author Keith Donald
* @since 3.0
*/
public interface ValidateResults {
}
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ui.validation;
import java.util.List;
/**
* TODO Document Validator.
*
* @author Keith Donald
* @since 3.0
*/
public interface Validator {
/**
* TODO Document validate().
*
* @param model
* @param properties
* @return
*/
ValidateResults validate(Object model, List<String> properties);
}
package org.springframework.ui.validation;
public interface ValidateResults {
}
package org.springframework.ui.validation;
import java.util.List;
public interface Validator {
ValidateResults validate(Object model, List<String> properties);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册