Wednesday, October 22, 2014

How to set max date and min date in <p:calendar />

The maxdate and mindate attribute is extremely useful for setting available date range for user selection.

e.g.
-Expiry date of an item should not be less than today.
-Date of birth should not be future date.

So how to set maxdate and mindate in PrimeFaces calendar component?

1. create the java.util.date object in backingBean
private Date currentDate = new Date();

public Date getCurrentDate() {

    return currentDate;
}

2. set the java.util.date object as mindate or maxdate
<p:calendar value="#{bean.expiryDate}" mindate="#{bean.currentDate}" />
 

<p:calendar value="#{bean.birthDate}" maxdate="#{bean.currentDate}" />


Done!!

1 comment:

  1. Here is the list of best free and paid Windows 10 apps that you should definitely use,
    especially if you are using Windows 10 laptop or Apps for PC.

    ReplyDelete

LinkWithin

Related Posts Plugin for WordPress, Blogger...