-->
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.  [ 3 posts ] 
Author Message
 Post subject: Validator does not preserve method hierarchy in InvalidValue
PostPosted: Tue Oct 25, 2005 6:44 pm 
Regular
Regular

Joined: Wed Jun 30, 2004 4:02 pm
Posts: 64
I love this feature and really hope this will become part of the EJB3 spec if not part or JSE itself someday.

The missing feature I find is when using the @Valid annotation to perform recursive validations.

Imagine a simple object graph. We have Customer which has Contact which has firstName, lastName, phone, fax, email. Phone and fax are instances of blah.model.Phone.

In Customer

@Valid
public Contact getContact() ...

In Contact

@Valid
public Phone getPhone() ...

@Valid
public Phone getFax() ...

In Phone

@Pattern(regex=PHONE_REGEXP, message="must match {regex}")
public String getNumber()...

now we code:

Code:
ClassValidator<Customer> customerValidator = new ClassValidator(Customer.class);

InvalidValue[] validationMessages = customerValidator.getInvalidValues(customer);

for (InvalidValue value : validationMessages) {
    log.debug("getBean() = " + value.getBean());
    log.debug("getBeanClass() = " + value.getBeanClass());
    log.debug("getMessage() = " + value.getMessage());
    log.debug("getPropertyName() = " + value.getPropertyName());
    log.debug("getValue() = " + value.getValue());
    errors.rejectValue(value.getPropertyName(), value.getMessage(), value.getMessage());
}
// The errors bit is from Spring, and just how I would capture the message and return it to the view layer.


If I have junk in my phone and fax values, the InvalidValue array tells me that I have a problem in Class Phone, propertyName number for both phone and fax.

What we need is a property to tell me the method hierarchy that was traversed to generate the validation error.

Something like a callStack returning a string: customer.contact.fax.number.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 6:01 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If I recall, I partly implemented this stuff. post your sample to JIRA for me to test. Or even better, provide a patch :-)

_________________
Emmanuel


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

Joined: Wed Jun 30, 2004 4:02 pm
Posts: 64
For any future readers of this thread, this functionality was implemented in beta 7.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.