Question

I need 2 things from the calendar component.

1) AM/PM selector. Right now, I can select the hour / and minute but the AM/PM is blank. Any idea why that is? 2) 12 hour clock instead of 24 hour. With AM/PM working this would satisfy the requirement. But incase it doesn't, is there anyway to specify a 12 hour clock?

Code:

<rich:calendar value="#{bean.aTimeField}" id="aTimeField"  
popup="true"  datePattern="d/M/yy HH:mm a"
enableManualInput="true" required="true"
showApplyButton="true" cellWidth="24px" cellHeight="24px" style="width:200px">
<f:ajax event="change" execute="@this"  bypassUpdates="#{true}"  render="aTimeField"/>       
</rich:calendar>
Was it helpful?

Solution

Short story:

You're actually forcing RichFaces to use a 24h format by giving HH:mm as part of the datePattern. Change it to hh:mm a to have AM/PM work as intended and used in the showcase.

Long story:

The API docs say:

datePattern [...] Used to format the date and time strings, according to ISO 8601 (for example, d/M/yy HH:mm a)

Where even the example indicates confusion since the standard uses 24h format and thus doesn't have a AM/PM distinction.

This works nevertheless because the input component uses the standard javax.faces.convert.DateTimeConverter to process datePattern. And this class' javadoc states:

If a pattern has been specified, its syntax must conform the rules specified by java.text.SimpleDateFormat.

And this format specs distinguish between

H   Hour in day (0-23)
h   Hour in am/pm (1-12)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top