How to set maxdate dynamically for 10 years plus just in xhtml file?

UI Components for JSF
Post Reply
pnwlover
Posts: 2
Joined: 22 Jul 2021, 04:31

22 Jul 2021, 05:03

Am using Java 1.8, Primefaces 10.0.0 on Tomcat 8.5.55... Am fairly new to JSF UI programming. Have a custom date JSTL tag where I need to dynamically set the maxdate to be 10 years from now when using the calendar widget (p:datePicker) - this is generic so that's why I can't place it inside a custom bean. It needs to be set declaratively inside my input.xhtml file (see below):

pom.xml:

Code: Select all

<properties>
    <primefaces-version>10.0.0</primefaces-version>
    <primefaces-extension-version>10.0.1</primefaces-extension-version>
</properties>

 <dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>${primefaces-version}</version>
</dependency>

<dependency>
    <groupId>org.primefaces.extensions</groupId>
    <artifactId>primefaces-extensions</artifactId>
    <version>${primefaces-extension-version}</version>
</dependency>
input.xhtml (custom taglib located inside ..src/main/webapp/WEB-INF/tags/input.xhtml):

Code: Select all

<ui:composition xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:d="http://www.mycompany.com/jsf/facelets"
                xmlns:ui="http://java.sun.com/jsf/facelets">

    <p:datePicker id="#{id}" value="#{bean[property]}" rendered="#{rendered}"
                disabled="#{disabled}"
                pattern="MM/dd/yyyy"
                required="#{required}" requiredMessage="#{requiredMessage}" timeZone="#{timeZone}"
                mindate="1/1/2011"
                maxdate="#{LocalDate.now().plusYears(10)}"
                mask="99/99/9999">
        <c:if test="#{not empty event}">
            <p:ajax event="#{event}" update="#{update}"/>
            <p:ajax event="dateSelect" update="#{update}" oncomplete="#{oncomplete}"/>
        </c:if>
    </p:datePicker>
</ui:composition>   
My mindate works - I can not go before 1/1/2011 in my calendar widget.

But I can go well past 2031 inside my calendar widget.

How can I set the maxdate to 10 years from now only in the input.xhtml file?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 13 guests