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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:03:55+00:00 2026-05-26T00:03:55+00:00

I have a form where I need to validate DateFrom and DateTo. I have

  • 0

I have a form where I need to validate DateFrom and DateTo.

I have done like this:

     // start date 
    RequiredTextField<Date> startdateField =
       new RequiredTextField<Date>("startDate",  Date.class);
    startdateField.add(new DatePicker(){
        @Override
        protected CharSequence getIconUrl() {
            return RequestCycle.get().getUrlRenderer().renderContextPathRelativeUrl("/image/date-picker.png");
        }
    });

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE,-1);
    startdateField.add(DateValidator.minimum(cal.getTime()));


    // end date 
    RequiredTextField<Date> enddateField = new RequiredTextField<Date>("endDate",  Date.class);
    enddateField.add(new DatePicker(){
        @Override
        protected CharSequence getIconUrl() {
            return RequestCycle.get().getUrlRenderer().renderContextPathRelativeUrl("/image/date-picker.png");
        }
    });


   // enddateField.add(DateValidator.minimum(startdateField.getModel().getObject()));
   // this does not work . Form submitted ?

Now How can I put a validator stating that endDate must be equal to or grater than selected start date in wicket?

Any idea? Help appreciated.

  • 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-26T00:03:56+00:00Added an answer on May 26, 2026 at 12:03 am

    DateValidator.minimum(startdateField.getModel().getObject()) isn’t working, because at page construction time, startdateField‘s Model doesn’t hold the value the user submits and which has to be taken into account as minimum at validation time.

    Usually, if your validation involves more than a single Component, it’s appropriate to use an IFormValidator. Its validate() method will be invoked after successful invokation of each dependent individual FormComponent.validate(), so you’re guaranteed to have valid individual inputs on each dependent component before proceeding on to validate them altogether.

    One important aspect of validation is preventing invalid user input from reaching the Component’s Models. Therefore, at validation time, Models will not be yet updated, and instead of FormComponent.getModelObject(), you’ll have to use FormComponent.getInput() or FormComponent.getConvertedInput() in the validate() method.

    IFormValidator validator = new AbstractFormValidator() {
        public FormComponent<?>[] getDependentFormComponents() {
            return new FormComponent[] { startDateField, endDateField };
        }
    
        public void validate(Form<?> form) {
            Date startDate = (Date) startDateField.getConvertedInput();
            Date endDate = (Date) endDateField.getConvertedInput();
    
            if (endDate.before(startDate)){
                error("Date range is invalid.");
            }
        }
    };
    form.add(validator);
    

    Take into account that if any of the FormComponents in getDependentFormComponents() isn’t valid (and that means being not visible, required and with no input, failing custom individual validations, etc), the FormValidator will not execute.

    You may also find this information useful: Validating related fields

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

Sidebar

Related Questions

I'm new to Django, trying to process some forms. I have this form for
I have about 100 TextBoxes in a Form. I need to validate them if
I have a registration form which I need to validate before submit. The form
I have a form which contains couple fields. Its very easy to validate this
I have a form which I need to validate the easiest and most safe
I have a form that uses the validation plugin, but I need to validate
I have a registration form on my website and need to validate the input
Have a form where a user can enter start date/time and end date/time for
I have a situation where I need to validate a form without actually having
I have a form MyForm : System.Windows.Forms.Form {} and I need to call Site.GetService(..)

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.