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

  • SEARCH
  • Home
  • 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 8300659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:38:35+00:00 2026-06-08T16:38:35+00:00

If we are build a custom JSR 303 validator, is there any way, we

  • 0

If we are build a custom JSR 303 validator, is there any way, we can pass field’s value to the validator instead of the field’s name?

Here is what I am doing..

I need to build a custom class level validation which validates this case..

There are two fields A & B where B is a date field. If A’s value is 1, verify that B is not null and its value is future date.

Now I was able to build a validation with these requirements following this post. In the FutureDateValidator’s isValid() method, I have checked whether A’s value is 1 or not and then I checked the date validity.

@CustomFutureDate(first = “dateOption”, second = “date”, message = “This must be a future date.”)

Now I have new set of fields C and D, where D is again the date field. This time I need to verify that D is a future date if C’s value is 2. In this case I cannot use the validator I already implemented because it has the first field’s value hard-coded. So how do I solve this issue to reuse the same validator for these two cases.

  • 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-06-08T16:38:38+00:00Added an answer on June 8, 2026 at 4:38 pm

    To not hardcode values 1/2 made it customizable:

    @CustomFutureDate(first = "dateOption", firstValue = "1", second = "date", message = "This must be a future date.")
    

    To make it work you need to modify @CustomFutureDate annotation:

    public @interface CustomFutureDate {
        String first();
        String firstValue();
        ...
    }
    

    and implementation:

    public class CustomFutureDateValidator implements ConstraintValidator<CustomFutureDate, Object> {
        private String firstFieldName;
        private String firstFieldValue;
        ...
    
        @Override
        public void initialize(final CustomFutureDate constraintAnnotation) {
            firstFieldName = constraintAnnotation.first();
            firstFieldValue = constraintAnnotation.firstValue();
            ...
        }
    
        @Override
        public boolean isValid(final Object value, final ConstraintValidatorContext context) {
            // use firstFieldValue member
            ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to build custom test phases in gradle? I have a
I'm trying to build a custom segue, but i can't seem to get the
I'm building a web app where users can build custom web pages that pull
Is it possible to build custom mscorlib.dll without any use of native code (pinvoke
I have a problem with advanced settings in theme-settings.php. i can build custom form
We're planning to create a web application where users can build custom forms, choosing
Hy Guys... i have some lightbox script where i can build custom buttons. I've
I build a custom AuthenticationSuccessHandler so users can login using Ajax aswell use a
There are a lot of ways to build custom controls for Asp.Net. Some people
I am using a javascript validator which will let me build custom validation based

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.