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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:13:43+00:00 2026-06-19T00:13:43+00:00

I want to validate two dates in a form before the user do the

  • 0

I want to validate two dates in a form before the user do the action. So I got a f:validator inside a p:calendar working with ajax, the problem is with the f:attribute. I am passing the start date as a parameter and the validator do not receive this date. However if press the action button, the date parameter is there in validation. I am using this post as a guide.
My xhtml is:

    <p:column >
                        <p:calendar  id="txtStartDate" binding="#{txtStartDate}"
                            pattern="dd/MM/yyyy"
                            value="#{myBean.bean.startDate}">                               
                        </p:calendar>
                    </p:column>
                    <p:column>
                        <p:calendar id="txtEndDate"
                            pattern="dd/MM/yyyy"
                            value="#{myBean.bean.endDate}">
                            <f:validator validatorId="validator.dateRangeValidator" />
                            <f:attribute name="fromDate" value="#{txtStartDate.value}" />                                
                            <p:ajax event="dateSelect" execute="@Form" update=":formHeader:messages" />
                        </p:calendar>
                    </p:column>

And Validator:

@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    if (value == null || component.getAttributes().get("fromDate") == null) return;

    Date endDate   = (Date) value; 
    Date startDate = (Date) component.getAttributes().get("fromDate");

    if (!endDate.after(startDate)) {
        FacesMessage message = new FacesMessage("End date before the start date.");
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        addMessageOnSession(FacesMessage.SEVERITY_ERROR, "Invalid dates");
        throw new ValidatorException(message);
    }
}

Appreciate any help with that.

  • 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-19T00:13:44+00:00Added an answer on June 19, 2026 at 12:13 am

    Anyway, a quick solution for me was add a listener=”” in ajax tag, so I am doing the validation at the bean. I dont know if this is the best way to do this, but solve my problem.

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

Sidebar

Related Questions

can I validate two interdependent fields in with one validator? <h:form> <h:inputText value=#{logRegBean.person.name} >
well my problem is that, i have a form, which i want to validate
I want to validate the data that the user enters in a form. I
I want to validate a form fields (text) input. It should only be a
I want to validate a condition before doing the next step, but only raise
I want to validate a registration form that accepts an email address in the
i want to validate uniqueness of two filed but if second filed is nil
I am trying to validate that two columns are unique in my User model.
I want to use ComponentModel DataAnnotations validate that at least one of two properties
I want to validate a form but I want to have 9 different functions

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.