tags:

views:

1723

answers:

4

Hello everybody!

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?

A: 

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)

Bozho
Can this be done on the server side?I do not want to use javascript. I would have to implement extra validations on the server!
DaUltimateTrooper
implement the validation on the server manually. Using custom JSF `Validator`. Or, using Hibernate Validator annotations (see richfaces - bean validator)
Bozho
Already done that!Thanks for everything!
DaUltimateTrooper
A: 

Hey 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

DaUltimateTrooper
A: 

Hey DaUltimateTrooper,

I have same kind of requirement.

I searched a lot but don't find any answer yet.

I will be very very thankful If you can help me.

I have 2 colums side by side for start date and end date.

Now the startdate and enddate values can or can't be null.

For example to select start date if end date is not null I should show start dates on calendar only from today's date upto end date, rest of others must be disabled.

If end date is null then user should be able to select any date starting from today.

Thank you so much KS

KJS
A: 

Hi, I want to dynamically allow the date range to be selected in a rich:calendar according to the selected date in another rich:calender. As an example user cannot select an end date older than the start date. I looked many sources but couldn't find a good solution. Can any one help me. Thank you, buffe