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 7522233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:27:49+00:00 2026-05-30T02:27:49+00:00

I have a form which contain some radio button and check-boxes . Whenever user

  • 0

I have a form which contain some radio button and check-boxes. Whenever user selects/deselects a radio button or check-box few other input fields are enabled/disabled.
I want to add validation only for fields which are enabled when user submits the form. Fields which are disabled at the time of submission should not be considered for validation.

I don’t want to add this in client side validation.Is there any better /easy way to implement conditional validation in Spring 3.0 instead of adding multiple if in validator ?

Thanks!

  • 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-30T02:27:51+00:00Added an answer on May 30, 2026 at 2:27 am

    When fields are disabled they are transferred to controller as null. I wanted to add a validation which will allow either null i.e disabled field or not blank field i.e. enabled but empty field.
    So I created a custom annotation NotBlankOrNull which will allow null and non empty strings also it takes care of blank spaces.
    Here is my Annotation

    @Documented
    @Constraint(validatedBy = { NotBlankOrNullValidator.class })
    @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
    @Retention(RUNTIME)
    public @interface NotBlankOrNull {
        String message() default "{org.hibernate.validator.constraints.NotBlankOrNull.message}";
    
        Class<?>[] groups() default { };
    
        Class<? extends Payload>[] payload() default { };
    }
    

    Validator class

    public class NotBlankOrNullValidator implements ConstraintValidator<NotBlankOrNull, String> {
    
        public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
            if ( s == null ) {
                return true;
            }
            return s.trim().length() > 0;
        }
    
        @Override
        public void initialize(NotBlankOrNull constraint) {
    
        }
    } 
    

    I have also updated more details on my site.

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

Sidebar

Related Questions

I have a pop up window,which is displaying form which can contain previous some
I have a string which contain tags in the form < tag > .
I have a php file that contains a form (which contains 2 input boxes
I have a child page LoginContent.aspx which contains a login form. If the user
I have a form containing some dynamic elements. These are basically text input boxes
I have a form containing two text boxes for user input. Both text boxes
I have an order form where a user gives some input about a product
I have a form which contains a lot of elements, my DB guy has
I have a an HTML form which contains the YAHOO rich text editor on
I have a form MainForm which is a Windows Forms form that contains many

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.