Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6600155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:35:07+00:00 2026-05-25T18:35:07+00:00

I am having a problem with some bean validation. Basically I have a form

  • 0

I am having a problem with some bean validation.

Basically I have a form where internet users can create a new profile, and they must input their username there.

I want to validate the username with regards to:

  1. Length
  2. Pattern
  3. If the username already exists

For bullet 3 I wrote my own custom validator @UserExists. The problem is that I do not want to have this validator run if any of the first two validators fail.

I have found that using the @GroupSequence on my UserExists validator does the trick with regard to the sequence, but JSF will still call my validator if one of the other validators reports that the input is invalid. Can I somehow check if one of the other validators failed already?

Here is the property I wanted to have checked:

@Size(min = 3, max = 20)
@Pattern(regexp = "[A-Za-z]+[A-Za-z0-9]*")
@UserExists(message = "User already exists")
private String username;

The custom validator has the following attributes:

@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Constraint(validatedBy = UserExistsValidator.class)
@GroupSequence({Size.class, Pattern.class})
public @interface UserExists
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:35:07+00:00Added an answer on May 25, 2026 at 6:35 pm

    The @GroupSequence annotation is intended to be specified on the bean hosting the constraints. As members validation groups must be specified, not single constraints.

    So your example might be implemented like that:

    @GroupSequence({Form.class, ExpensiveChecks.class})
    public class Form {
    
        public interface ExpensiveChecks {}
    
        @Size(min = 3, max = 20)
        @Pattern(regexp = "[A-Za-z]+[A-Za-z0-9]*")
        @UserExists(message = "User already exists", groups=ExpensiveChecks.class)
        private String username;
    
    }
    

    That way the default group sequence for the Form type is redefined. At first the @Size and @Pattern constraints are validated. Only if that succeeds the @UserExists constraint (which is part of the ExpensiveChecks group) will be validated.

    You can learn more about group sequences and the redefinition of default group sequences in the Hibernate Validator reference guide and the Bean Validation specification.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problems with bean initialization. I have an edit form to update
I'm having some problem with MKMapView / annotations / UINavigationController. Basically, i manage my
I am working on a windows form project and having some problem with UserControl
I'm having a problem lining up some icons and am new enough to css
I am having some strange problem and its really frustating me. I have a
I'm having a problem deciding when to create a new controller and which controller
I'm having a problem with some code I've written. I've had to anonymize it,
I'm having a problem with some T-SQL in a SP on SQLServer 2005 comparing
I'm having a problem with some code that used to work in PHP 4.X
For some reason I'm having a problem retrieving data from my database. It leaves

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.