Results 1 to 3 of 3

Thread: Validation and Message Joining

  1. #1
    Join Date
    Nov 2011
    Posts
    4

    Question Validation and Message Joining

    Hi everyone,

    I've tried to implement a validation service to my project. My Validator Code looks like this:
    Code:
    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 witht he following entrys:
    Code:
    ......
    error.zip=There is an Error at Zip-Code
    error.countryname=There is an Error at Countryname
    Everythink 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");
    ......
    Thanks for your help

    Regards
    Crazymodder

  2. #2
    Join Date
    Dec 2011
    Posts
    1

  3. #3
    Join Date
    May 2011
    Location
    Hamburg Germany
    Posts
    33

    Default

    Crazymodder, you should be able to control individual style of your error messages like this
    Code:
    <spring:hasBindErrors name="form">
    	<div class="message-error">
    	<c:forEach items="${errors.allErrors}" var="error">
    		<div><spring:message message="${error}"/></div>
    	</c:forEach>
    	</div>
    </spring:hasBindErrors>
    Its form one of the recent postings here on the forum.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •