-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Validator, @Embedded and deep property names
PostPosted: Mon Dec 12, 2005 6:10 pm 
Newbie

Joined: Mon Dec 12, 2005 6:00 pm
Posts: 11
I have an embedded attribute on my domain object that looks like this:

Code:
@Embedded
@Valid
public Address getAddress()
{
    return address;
}


All is well, the various fields on the address object get validated correctly. I'm using the hibernate validation framework to produce InvalidValues and using those InvalidValues to reject fields in Spring MVC's validation framework. The problem is this; if the city field fails validation on address the invalid value says the property name is "city" and the class is Address. Is there anyway to get the property name to be something like "address.city" since this is the property I use with binding in Spring MVC. I'm hoping to avoid writing code that reflectively looks at the domain object and builds these deep property names.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 7:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
yes I've done something like that in CVS

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 10:51 am 
Newbie

Joined: Mon Dec 12, 2005 6:00 pm
Posts: 11
emmanuel wrote:
yes I've done something like that in CVS


Excellent, I'll check out the HEAD revisions in CVS then. Any tips to point me in the right direction?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 12:17 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
download beta7 and check the doc, I've just uploaded both.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 5:08 pm 
Regular
Regular

Joined: Wed Jun 30, 2004 4:02 pm
Posts: 64
jefmsmit,

I am doing similar work, combining Hibernate Validator with Spring MVC. I have created some JSP tag files that automatically add class="required" or class="optional" to for fields, and add a maxlength attribute based on reflecting over the corresponding annotations. I'm now working on creating a generic validator method to be used by a Spring MVC validator. We could probably share some code and post the results somewhere.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 11:24 am 
Newbie

Joined: Mon Dec 12, 2005 6:00 pm
Posts: 11
tedberg,

I'd be happy to help out. Although I really haven't needed to write much code at all, that was the beauty of using the hibernate validator. Here is all I needed to do in my Spring validator:

Code:
    public boolean supports(Class aClass)
    {
        return DomainObject.class.isAssignableFrom(aClass);
    }

    public void validate(Object object, Errors errors)
    {
        DomainObject domainObject = (DomainObject) object;
        List<InvalidValue> invalids = domainObject.validate();

        for (int i = 0; i < invalids.size(); i++)
        {
            InvalidValue invalidValue = invalids.get(i);
            errors.rejectValue(invalidValue.getPropertyName(), null, invalidValue.getMessage());
        }
    }


I just need to change the invalidValue.getPropertyName() to use the new getPropertyPath method.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 2:39 pm 
Regular
Regular

Joined: Wed Jun 30, 2004 4:02 pm
Posts: 64
I wrote an article describing how to use Hibernate Validator and Spring MVC together.

http://www.ibm.com/developerworks/java/library/j-hibval.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2009 4:31 pm 
Regular
Regular

Joined: Wed Jun 30, 2004 4:02 pm
Posts: 64
IBM broke the link to that article. It can be found at:


http://www.triview.com/articles/hibernate/validator/canmeetyourneeds.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.