1
|
package vldc.aswi.web.controller;
|
2
|
|
3
|
import org.springframework.stereotype.Controller;
|
4
|
import org.springframework.validation.BindingResult;
|
5
|
import org.springframework.validation.FieldError;
|
6
|
import org.springframework.validation.ObjectError;
|
7
|
|
8
|
@Controller
|
9
|
public class BasicController {
|
10
|
|
11
|
/**
|
12
|
* Return message containings all errors from validator.
|
13
|
* @param result Validator results.
|
14
|
* @return String message containings all errors from validator.
|
15
|
*/
|
16
|
protected String getFullErrorMessage(BindingResult result) {
|
17
|
String message = "";
|
18
|
|
19
|
for (Object object : result.getAllErrors()) {
|
20
|
if (object instanceof FieldError) {
|
21
|
FieldError fieldError = (FieldError) object;
|
22
|
|
23
|
message += fieldError.getDefaultMessage() + ", ";
|
24
|
continue;
|
25
|
}
|
26
|
|
27
|
if (object instanceof ObjectError) {
|
28
|
ObjectError objectError = (ObjectError) object;
|
29
|
|
30
|
message += objectError.getDefaultMessage() + ", ";
|
31
|
continue;
|
32
|
}
|
33
|
}
|
34
|
return message;
|
35
|
}
|
36
|
}
|