Search code examples
jqueryjbossrichfaces

Highlight current week in RichFaces calendar


Is there a way to highlight the current or selected week in a RichFaces calendar?

<rich:calendar value="#{oc.overtimeDate}" requiredMessage="Date 1 is required."
  id="#{oc.overtimeDateId}" isDayEnabled="isDayEnabled"
  dayStyleClass="getDisabledStyle" datePattern="MM-dd-yyyy"
  required="true" firstWeekDay="0"/>

Solution

  • <rich:calendar> has @dayClassFunction (see the docs)

    It can look like this:

    <h:outputStylesheet>
        .highlightWeek {
            color: red;
            background-color: black;
        }
    </h:outputStylesheet>
    <h:outputScript>
        var currentWeekNumber = … // determine current week number
        chooseDay = function(day) {
            if (day.weekNumber == currentWeekNumber) return 'highlight';
                return '';
            }
    </h:outputScript>
    <h:form>
        <rich:calendar dayClassFunction="chooseDay" />
    </h:form>