Search code examples
jspjsfrichfaces

Year dropdown in jsf


How can I use <rich:calendar> to only display year. I want year dropdown in jsf How can I achieve it.Please guide

I tried

<rich:calendar value="#{existingPolicyRecord.dateOfApp}" datePattern="yyyy" ></rich:calendar>

But unable to get year dropdown.Is there any other component for that?


Solution

  • This isn't officially supported and I guess it would be better to do that with a normal dropdown selectBox because you only have a list of values (years).

    Nevertheless there is a way to get the calendar to show only month and year:

    create a style class to hide the "days":

    <style type="text/css">
            .special tr[id]{
                    display:none; 
            }
    </style>
    

    disable footer, days and weeks and apply style class to your calendar:

        <rich:calendar value="#{calendarBean.selectedDate}" popup="false" 
         showWeeksBar="false" showWeekDaysBar="false" showFooter="true" styleClass="special"/>
    

    It will look like this: enter image description here enter image description here