List of usage examples for org.springframework.validation Errors addAllErrors
void addAllErrors(Errors errors);
From source file:org.codehaus.groovy.grails.web.metaclass.RedirectDynamicMethod.java
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/* w w w .j a va2s . c om*/
public Object invoke(Object target, String methodName, Object[] arguments) {
if (arguments.length == 0) {
throw new MissingMethodException(METHOD_SIGNATURE, target.getClass(), arguments);
}
Map argMap = arguments[0] instanceof Map ? (Map) arguments[0] : Collections.EMPTY_MAP;
if (argMap.isEmpty()) {
throw new MissingMethodException(METHOD_SIGNATURE, target.getClass(), arguments);
}
GrailsWebRequest webRequest = (GrailsWebRequest) RequestContextHolder.currentRequestAttributes();
LinkGenerator requestLinkGenerator = getLinkGenerator(webRequest);
HttpServletRequest request = webRequest.getCurrentRequest();
if (request.getAttribute(GRAILS_REDIRECT_ISSUED) != null) {
throw new CannotRedirectException(
"Cannot issue a redirect(..) here. A previous call to redirect(..) has already redirected the response.");
}
HttpServletResponse response = webRequest.getCurrentResponse();
if (response.isCommitted()) {
throw new CannotRedirectException(
"Cannot issue a redirect(..) here. The response has already been committed either by another redirect or by directly writing to the response.");
}
if (target instanceof GroovyObject) {
GroovyObject controller = (GroovyObject) target;
// if there are errors add it to the list of errors
Errors controllerErrors = (Errors) controller.getProperty(ControllerDynamicMethods.ERRORS_PROPERTY);
Errors errors = (Errors) argMap.get(ARGUMENT_ERRORS);
if (controllerErrors != null && errors != null) {
controllerErrors.addAllErrors(errors);
} else {
controller.setProperty(ControllerDynamicMethods.ERRORS_PROPERTY, errors);
}
Object action = argMap.get(GrailsControllerClass.ACTION);
if (action != null) {
argMap.put(GrailsControllerClass.ACTION, establishActionName(action, controller));
}
if (!argMap.containsKey(GrailsControllerClass.NAMESPACE_PROPERTY)) {
// this could be made more efficient if we had a reference to the GrailsControllerClass object, which
// has the namespace property accessible without needing reflection
argMap.put(GrailsControllerClass.NAMESPACE_PROPERTY, GrailsClassUtils
.getStaticFieldValue(controller.getClass(), GrailsControllerClass.NAMESPACE_PROPERTY));
}
}
boolean permanent = DefaultGroovyMethods.asBoolean(argMap.get(ARGUMENT_PERMANENT));
// we generate a relative link with no context path so that the absolute can be calculated by combining the serverBaseURL
// which includes the contextPath
argMap.put(LinkGenerator.ATTRIBUTE_CONTEXT_PATH, BLANK);
return redirectResponse(requestLinkGenerator.getServerBaseURL(), requestLinkGenerator.link(argMap), request,
response, permanent);
}
From source file:org.opentestsystem.authoring.testitembank.service.impl.ImportSetServiceImpl.java
private Errors validate(final ItemValidator inItemValidator, final ApipItemContent inItemContent) { final Errors errors = new BindException(inItemContent.getItem(), "item"); if (inItemContent.getErrors() == null || inItemContent.getErrors().hasErrors()) { for (final ObjectError error : inItemContent.getErrors().getAllErrors()) { sendZipFileMonitoringAndAlertingErrors(error.getCode(), error.getArguments()); }// w w w . j a v a2 s. co m errors.addAllErrors(inItemContent.getErrors()); } else { inItemValidator.validate(inItemContent.getItem(), errors); } return errors; }