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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:42:57+00:00 2026-05-27T22:42:57+00:00

I have two input fields fromDate and toDate which are instances of Date class.

  • 0

I have two input fields fromDate and toDate which are instances of Date class.
The Date class uses custom Date validator which validates the month, day and year fields
contained in the date field.
The custom date validator is specific for each date i.e, fromDate and toDate.
I need to compare the month, day or year fields of fromDate with toDate.
If the fromDate is greater than toDate, a validation message has to displayed.

Update:

The fromDate and toDate are two custom date components as below

<eg:dateField id="inpFromDate" value="#{mrBean.fromDate}" .... />
<eg:dateField id="inpToDate" value="#{mrBean.toDate}" .... />

fromDate and toDate are instances of Date class which is

public class Date {
private String mm;
private String dd;
@customDateValidator   //Validates each date field
private String yyyy;
//constructors
//getters and setters

How would you implement the validator in this case where each date already has a validator

  • 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-27T22:42:58+00:00Added an answer on May 27, 2026 at 10:42 pm

    Yes, you can! Suppose you have the following PrimeFaces’s input fields:

    <p:calendar id="from" value="#{mrBean.fromDate}" binding="#{from}" >
       <p:ajax process="from to" update="toDateMsg" />
    </p:calendar>
    <p:calendar id="to"   value="#{mrBean.toDate}" >
       <f:attribute name="fromDate" value="#{from.value}" />
       <f:validator validatorId="validator.dateRangeValidator" />
       <p:ajax process="from to" update="toDateMsg" />
    </p:calendar>
    <p:message for="to" id="toDateMsg" />
    

    This should be your Validator:

    @FacesValidator("validator.dateRangeValidator")
    public class DateRangeValidator implements Validator {
    
        @Override
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            if (value == null || component.getAttributes().get("fromDate") == null) return;
    
            Date toDate   = (Date) value; 
            Date fromDate = (Date) component.getAttributes().get("fromDate");
    
            if (toDate.after(fromDate)) {
                FacesMessage message = new FacesMessage("Invalid dates submitted.");
                message.setSeverity(FacesMessage.SEVERITY_ERROR);
                throw new ValidatorException(message);
            }
        }
    }
    

    Note that I am using PrimeFaces’s <p:calendar> component to write my example because the properties binded to this component will automatically be converted to Date object before being validated. In your program, you may have your own Converter to convert String to Date.

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

Sidebar

Related Questions

I have two input fields, Id and Desc. I need a javascript which enters
I currently have two input fields which toggle the value value to either true
for email validation I have these two input fields: <input class=inputbox type=text name=data[subscriber][email] id=field_email
I have two fields in a form <div class=form> <label class=title>{'webmasterSubmitWebsite_rss_feed_title'|lang}</label> <div class=infos><input type=text
I have two input fields, and without changing their names (i.e., I have to
I hope I can explain this right I have two input fields that require
I have a page with two input fields City and Venue. I have the
I have a usual login form consisting of two input fields, one for login,
I have two input text boxes which are decimal. The sum of the two
I have two input fields. I want to force the focus on #area no

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.