I’ve tried to implement a validation service to my project. My Validator Code looks like this:
public class UserValidator implements Validator{
public boolean supports(Class<?> clazz) {
return Ort.class.isAssignableFrom(clazz);
}
public void validate(Object target, Errors errors) {
Ort ort = (Ort) target;
if((ort.getcountryname().length() == 0) && (ort.getzip().length() == 0))
{
errors.reject("error.zip");
errors.reject("error.countryname");
}
}
}
I have an message xml with he following entries:
Code:
......
error.zip=There is an Error at Zip-Code
error.countryname=There is an Error at Countryname
Everything works fine. I make an outprint on my jsp like this:
Code:
<form:errors path="*" cssClass="error message" element="div"/>
My HTML Code looks like this if I get an error:
Code:
There is an Error at Zip-Code<br>There is an Error at Countryname
My Question:
How can I join the message so that i get an outprint on my jsp with looks so:
Code:
There is an Error at Zip-Code, There is an Error at Countryname
Can i do somethink like that in my validation class?
Code:
......
errors.reject("error.zip"+"error.countryname");
......
I guess you mixed two concepts:
errors.reject("error.zip"+"error.countryname"))There is an Error at Zip-Code, There is an Error at Countryname
If you want to change the way they are printed, then you have to change the
form:errorstag, but NOT the way you add the messages to the error object! (In contrast: if you want to change the messages itself, then changing the output would be the wrong way.)So remove the
<br/>from the output and replace it by,you just need to specify thedelimiterattribute of theform:errorstag:@see Spring Reference Appendix G.4 The errors tag