Results 1 to 3 of 3

Thread: Multi-Level Object Validation

  1. #1
    Join Date
    Oct 2010
    Posts
    19

    Default Nested Objects Validation

    I'm currently using JSR-303 Bean Validation API for validating the bean.

    I did a small program wh just primitive types.
    Book.java
    Code:
    public class Book
    {
    	@NotEmpty
    	private String name;
    
    	@Size(min=1, max=50)
    	private String description;
    
    	// Getters and setters here
    }
    form.jsp
    Code:
    <form:form method="post" action="book.html" commandName="book">
    	<table>
    		<tr>
    			<td>Name:</td> <td><form:input path="name" /></td> <td><form:errors path="name" /></td>
    		</tr>
    		<tr>
    			<td>Description:</td><td><form:textarea path="description"/></td> <td><form:errors path="description" /></td>
    		</tr>
    		</table>
    	<input type="submit" value="Create" />
    </form:form>
    Everything was working fine.

    Then I introduced an object Author inside book.
    Book.Java
    Code:
    Public Class Book{
    	@NotEmpty
    	private String name;
    	@Size(min=1, max=50)
    	private String description;
    	private Author author;
    	//Getters and Setters
    }
    Author.java
    Code:
    Public Class Author{
    	@NotEmpty
    	private String authorName;
    	//Getters and Setters
    }
    Now I get an error:

    javax.validation.UnexpectedTypeException: No validator could be found for type: com.ratzzak.form.Author


    What is the right way to do the validation?
    Last edited by Ratzzak; Nov 11th, 2010 at 06:08 AM. Reason: Making the post more readable

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    I suggest referring to the JSR 330 spec and/or documentation for your provider, but I believe adding @Valid to your author property on your parent bean is required. I'd research when that error you got can be thrown.

    Keith
    Keith Donald
    Core Spring Development Team

  3. #3
    Join Date
    Oct 2010
    Posts
    19

    Default

    Thanx Keith...

    But i found the solution here http://forum.springsource.org/showthread.php?t=83513

Posting Permissions

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