[hibernate-issues] [Hibernate-JIRA] Commented: (HV-264) Implement ConstraintValidator<Email, Collection<String>>

Michenaud Laurent (JIRA) noreply at atlassian.com
Thu Oct 29 09:17:12 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HV-264?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=34343#action_34343 ] 

Michenaud Laurent commented on HV-264:
--------------------------------------

Hi,

First, thanks a lot for your responses.

I have tested it, it works well but i still have questions :

1) I have seen in the JSR303 1.0 RC1 that your interface 
ConstraintValidatorContext is different from the one at 
page 14.
Maybe you're working with a more advanced version of the JSR 303 ?

2) It is a great thing to be able to disable the default error
message of a check and to add severals errors via the ConstraintValidatorContext.
This is what i need but i would like to redefine the invalid value.

Let have a lookup at my example : a bean with a list of string, my check
tests that the strings inside are uppercase. My test bean instance has 
3 values, first and third are bad.
Here is the output of my log :

***** Violation *****
 message = error with value : 'email1' at position 0
 message template = error with value : 'email1' at position 0
 invalid value = [email1, EMAIL2, email3]
 property path = emails.0
 leaf bean = org.MyBean at 1578aab
 root bean = org.MyBean at 1578aab
 root bean class = org.MyBean
***** Violation *****
 message = error with value : 'email3' at position 2
 message template = error with value : 'email3' at position 2
 invalid value = [email1, EMAIL2, email3]
 property path = emails.2
 leaf bean = org.MyBean at 1578aab
 root bean = org.MyBean at 1578aab
 root bean class = org.MyBean

The problems are :
- The invalid value is still the list. It would good if we could redefine the
invalid value using the ConstraintViolationBuilder.
- I don't need that but it would good if we could redefine the leaf bean too.

Best regards













 



> Implement ConstraintValidator<Email, Collection<String>>
> --------------------------------------------------------
>
>                 Key: HV-264
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-264
>             Project: Hibernate Validator
>          Issue Type: New Feature
>          Components: validators
>    Affects Versions: 4.0.1
>         Environment: Linux
>            Reporter: Michenaud Laurent
>             Fix For: 4.1.0
>
>
> Hi,
> I have a list of String in my bean :
> These strings are email and i want to validate them.
> So, i did in my bean :
> @NotEmpty
> @Email
> //@Valid <= uncommenting that line doesnot change anything.
> List<String> emails ;
> At execution, i've got the error :
> Exception in thread "main" javax.validation.UnexpectedTypeException: No validator could be found for type: java.util.List<java.lang.String>
>    at org.hibernate.validator.engine.ConstraintTree.verifyResolveWasUnique(ConstraintTree.java:236)
>    at org.hibernate.validator.engine.ConstraintTree.findMatchingValidatorClass(ConstraintTree.java:219)
>    at org.hibernate.validator.engine.ConstraintTree.getInitializedValidator(ConstraintTree.java:167)
>    at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:113)
>    at org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:121)
>    at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:334)
>    at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:278)
>    at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:260)
>    at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:213)
>    at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
>    at com.adeuza.movalys.validation.hibernate.TestMain.main(TestMain.java:75)
> I don't know if it is a bug in hibernate validator. I have looked at the JSR303 and i have not seen anything
> about List of primitives. You can validate per example List<Person> with @Valid and it works well because
> the validator knows about Person class.
> I have used a little the Oval framework and with it, you can tell if the check applies to the container,
> or the values inside, or the keys(for map). I don't know if you can do that with JSR303.
> I'm interesting with your point of view.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list