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.

-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 object in backingBean
private Date currentDate = new Date();

public Date getCurrentDate() {

    return currentDate;

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

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



Related Posts Plugin for WordPress, Blogger...