-->
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.  [ 2 posts ] 
Author Message
 Post subject: Annotation with validatedBy set to empty {}
PostPosted: Thu Jun 06, 2013 4:50 pm 
Newbie

Joined: Tue Dec 27, 2005 10:39 am
Posts: 9
Hi,

I am wondering if it is possible to register programmatically a ConstraintValidator class for a custom annotation to the Validator.
I would like to define an annotation CheckCase (example below ) that would be part of my API but I don't want it to import/depend on the ConstraintValidator class.
The ConstraintValidator is for me an implementation class that I don't want to expose and deliver and even depend on it.
Therefore I want to set the validatedBy attribute to empty array for the @Constraint annotation.

Is it possible to configure the validator so that it associates the @CheckCase annotation a specific ConstraintValidator implementation case ?
(like for the annotations provided in the javax.validation api)

Code:
@Target( { METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Constraint(validatedBy = {})
@Documented
public @interface CheckCase {

    String message() default "{com.mycompany.constraints.checkcase}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};
   
    CaseMode value();

}



Thanks in advance,
Regards,
Luc


Top
 Profile  
 
 Post subject: Re: Annotation with validatedBy set to empty {}
PostPosted: Thu Jun 06, 2013 5:49 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
It's currently not possible to register a validator programmatically, but you can do it using an XML constraint mapping (see http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#section-mapping-xml-constraints):

Code:

<constraint-mappings
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.1.xsd"
    xmlns="http://jboss.org/xml/ns/javax/validation/mapping" version="1.1">

    <constraint-definition annotation="org.mycompany.CheckCase">
        <validated-by include-existing-validators="false">
            <value>org.mycompany.CheckCaseValidator</value>
        </validated-by>
    </constraint-definition>
</constraint-mappings>


Maybe you want to contribute an addition to the HV programmatic constraint declaration API (http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#section-programmatic-api) for registering constraint validators?

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


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