-->
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: Chaining Constraints
PostPosted: Tue Oct 06, 2009 4:32 am 
Newbie

Joined: Thu Aug 27, 2009 8:21 am
Posts: 13
Hi,

I have the following:

Code:
@Target({FIELD, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Constraint(validatedBy = OptionalTextFieldCheck.class)
@Documented
@Length(min = 1)
public @interface OptionalTextField {
    public abstract Class<? extends Payload>[] payload() default {};
    public abstract Class<?>[] groups() default {};
    public abstract String message() default "{error.textField}";

    /**
     * Maximum length of the field
     */
    public abstract int value();
}


I want to set the max value on the @Length constraint to the value passed to @OptionalTextField. I've looked, and there doesn't seem to be any way of setting it programatically. Is there any way to do this?

TIA:

Bryan


Top
 Profile  
 
 Post subject: Re: Chaining Constraints
PostPosted: Thu Oct 29, 2009 11:44 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
You would use @OverridesAttribute. Something like this:

Code:
@Target({FIELD, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Constraint(validatedBy = OptionalTextFieldCheck.class)
@Documented
@Length(min = 1)
public @interface OptionalTextField {
    public abstract Class<? extends Payload>[] payload() default {};
    public abstract Class<?>[] groups() default {};
    public abstract String message() default "{error.textField}";

    /**
     * Maximum length of the field
     */
    @OverridesAttribute(constraint=Length.class, name="min")
    public abstract int value();
}


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.