-->
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.  [ 4 posts ] 
Author Message
 Post subject: Who to set check order for JSR303 bean validation
PostPosted: Thu Sep 30, 2010 8:28 am 
Newbie

Joined: Thu Sep 30, 2010 8:21 am
Posts: 5
I use the JSR303 Bean Validation to check the form input.

Code:
@NotBlank
@Size(min = 4, max = 30)
private String name;

@NotBlank
@Size(max = 100)
@Email
private String mail;

when then name and email is blankļ¼Œthe @NotBlank, @Size at name, @NotBlank, @Size, @Email at mail will be checked.

I want set the check order, when the previous order is invalid, the next is not checked,
like below.

Code:
@NotBlank(order = 1)
@Size(min = 4, max = 30, order = 2)
private String name;

(but the above is not support by JSR303)

Is there a way to implement it for using JSR303?
(I think the custom annotation will done, but i don't like to add so much custom annotation for every property.)


Top
 Profile  
 
 Post subject: Re: Who to set check order for JSR303 bean validation
PostPosted: Wed Dec 28, 2011 8:09 am 
Newbie

Joined: Tue Feb 02, 2010 9:00 am
Posts: 19
This is the most important missing part of the JSR303.

Look at these codes:

@GroupSequence({OldPassword.OldPassword1.class, OldPassword.OldPassword2.class, OldPassword.OldPassword3.class})
Code:
public interface OldPassword {
interface OldPassword1 {}
interface OldPassword2 {}
interface OldPassword3 {}
}


@GroupSequence({NewPassword.NewPassword1.class, NewPassword.NewPassword2.class})
public interface NewPassword {
   interface NewPassword1 {}
   interface NewPassword2 {}
}



Code:

   @NotEmpty(groups = OldPassword.OldPassword1.class)
   @Size(groups = OldPassword.OldPassword2.class, min = UserConstants.PASSWORD_MIN, max = UserConstants.PASSWORD_MAX")
   @IsPasswordCorrect(groups = OldPassword.OldPassword3.class)
   private String oldPassword;

   @NotEmpty(groups = NewPassword.NewPassword1.class)
   @Size(groups = NewPassword.NewPassword2.class, min = UserConstants.PASSWORD_MIN, max = UserConstants.PASSWORD_MAX)
   private String newPassword;
 



Please listen the community. I started believe that no one is taking care with us. :(


Top
 Profile  
 
 Post subject: Re: Who to set check order for JSR303 bean validation
PostPosted: Thu Dec 29, 2011 4:02 am 
Newbie

Joined: Tue Feb 02, 2010 9:00 am
Posts: 19
Please vote

https://hibernate.onjira.com/browse/BVAL-255


Top
 Profile  
 
 Post subject: Re: Who to set check order for JSR303 bean validation
PostPosted: Wed May 30, 2012 6:50 pm 
Newbie

Joined: Wed May 30, 2012 6:17 pm
Posts: 1
I have the same problem, but in my case the second constraint is a custom one, and that example does not work for me

this is my bean:

Code:
public class MyBean {
   @NotBlank(groups = Default.class)
   @CustomConstraint(groups = Extended.class)
   private String aaa = "";
   
   @NotBlank
   private String bbb = "";

   ....

   @GroupSequence({Default.class, Extended.class})
   public interface MyInterface {
      interface Default {}
      interface Extended {}
   }
}


and this is my CustomConstraint:
Code:
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy=CustomConstraintValidator.class)
public @interface CustomConstraint {
   String message() default "";
   Class<?>[] groups() default {};
   Class<? extends Payload>[] payload() default {};
}


and validation code:
Code:
public class CustomConstraintValidator implements ConstraintValidator<CustomConstraint , String> {
   public void initialize(CustomConstraint customConstraint ) {
      ...
   }

   public boolean isValid(String value, ConstraintValidatorContext context) {
      ...      
   }
}


What I have to do?


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