Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Richfaces Calendar Minimum and Maximum Dates

Tags:

jsf

richfaces

My problem is making the RichFaces calendar restricting the dates to be allowed to be chosen by the user.

Let's say I want to allow only the dates of this month and the dates of the next month to be chosen by the user.

I used the preloadDateRangeStart and preloadDateRangeEnd attributes but they did nothing.

I created my own CalendarDataModel which uses the preloadDateRangeStart and preloadDateRangeEnd and enables the items but the calendar on the screen allows only the dates of the current month to be selected. Note that the preloadDateRangeStart is today's date and preloadDateRangeEnd is today's date plus 2 months.

I am missing something here for sure. Can someone help me please?

like image 861
Timmo Avatar asked Dec 16 '09 09:12

Timmo


2 Answers

Use the isDayEnabled="isDayEnabled" attribute, where the value (isDayEnabled) is a javascript function you should define, in the form

function isDayEnabled(day) {
}

See the richfaces demo for more details.

If you want to add validation on the server side, use a custom JSF Validator, or use Hibernate Validator annotations (see richfaces - bean validator)

like image 111
Bozho Avatar answered Oct 13 '22 02:10

Bozho


I figured out how it works so here it goes:

I created a class which implements the CalendarDataModel.

I did not use the preloadDateRangeStart and preloadDateRangeEnd attributes though because the CalendarDataModel only cares about the range between preloadDateRangeStart and preloadDateRangeEnd in case you specify them.

My CalendarDataModel disables calendar items whose date is out of the date range I specified in a property file and which I use in the CalendarDateModel to determine if the item's date is not between the range in order to disable it.

So now it works great. Here is the tag:

<a4j:outputPanel id="myCal" layout="block">
   <rich:calendar cellHeight="30px" cellWidth="30px" 
       dataModel="#{MyCalendarDataModel}" datePattern="dd/MM/yyyy" mode="ajax"
       style="width:200px" value="#{MyPage.theDate}"/>
 </a4j:outputPanel>

I also tried your solution. It works but it's a bit messy on the client.

Thank you again man

like image 28
Timmo Avatar answered Oct 13 '22 02:10

Timmo