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?
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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With