Calendar is an input component to pick a datetime.
<script>
PrimeFaces.locales ['de'] = {
monthNames: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
monthNamesShort: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
dayNames: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
dayNamesShort: ['Son', 'Mon', 'Die', 'Mit', 'Don', 'Fre', 'Sam'],
dayNamesMin: ['S', 'M', 'D', 'M ', 'D', 'F ', 'S'],
weekHeader: 'Woche',
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: '',
timeOnlyTitle: 'Nur Zeit',
timeText: 'Zeit',
hourText: 'Stunde',
minuteText: 'Minute',
secondText: 'Sekunde',
today: 'Aktuelles Datum',
ampm: false,
month: 'Monat',
week: 'Woche',
day: 'Tag',
allDayText: 'Ganzer Tag',
aria: {
close: 'Schließen',
previous: 'Zurück',
next: 'Weiter',
}
};
</script>
<style>
.value {
font-weight: bold;
}
</style>
<div class="card">
<h:form id="form">
<p:growl id="msgs" showDetail="true" skipDetailIfEqualsSummary="true"/>
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="inline" value="Inline:"/>
<p:calendar id="inline" value="#{calendarView.date1}" mode="inline"/>
<p:outputLabel for="popup" value="Popup:"/>
<p:calendar id="popup" value="#{calendarView.date2}"/>
<p:outputLabel for="button" value="Button:"/>
<p:calendar id="button" value="#{calendarView.date3}" showOn="button"/>
<p:outputLabel for="event" value="Select Event:"/>
<p:calendar id="event" value="#{calendarView.date4}">
<p:ajax event="dateSelect" listener="#{calendarView.onDateSelect}" update="msgs"/>
</p:calendar>
<p:outputLabel for="german" value="German:"/>
<p:calendar id="german" value="#{calendarView.date5}" locale="de" navigator="true"
pattern="yyyy-MMM-dd"/>
<p:outputLabel for="germanV2" value="German (other Pattern):"/>
<p:calendar id="germanV2" value="#{calendarView.dateDe}" locale="de" navigator="true"
pattern="dd.MM.yyyy"/>
<p:outputLabel for="restricted" value="Restricted:"/>
<p:calendar id="restricted" value="#{calendarView.date6}" mindate="#{calendarView.minDate}"
maxdate="#{calendarView.maxDate}"/>
<p:outputLabel for="multi" value="Multiple:"/>
<p:calendar id="multi" value="#{calendarView.date7}" pages="3"/>
<p:outputLabel for="effect" value="Effect:"/>
<p:calendar id="effect" value="#{calendarView.date8}" effect="fold"/>
<p:outputLabel for="mask" value="Mask:"/>
<p:calendar id="mask" value="#{calendarView.date9}" pattern="dd-MM-yyyy" mask="true"/>
<p:outputLabel for="datetime" value="Datetime:"/>
<p:calendar id="datetime" value="#{calendarView.date10}" pattern="MM/dd/yyyy HH:mm:ss"/>
<p:outputLabel for="dateTimeDe" value="Datetime (German):"/>
<p:calendar id="dateTimeDe" value="#{calendarView.dateTimeDe}" locale="de"
pattern="dd.MM.yyyy HH:mm"/>
<p:outputLabel for="time" value="Time Only:"/>
<p:calendar id="time" value="#{calendarView.date11}" pattern="HH:mm" timeOnly="true"/>
</h:panelGrid>
<p:commandButton value="Submit" update="msgs" action="#{calendarView.click}" icon="pi pi-check"/>
<p:dialog modal="true" resizable="false" header="Values" widgetVar="dlg" showEffect="fold">
<p:panelGrid id="display" columns="2" columnClasses="label,value">
<h:outputText value="Inline:"/>
<h:outputText value="#{calendarView.date1}">
<f:convertDateTime pattern="MM/dd/yyyy"/>
</h:outputText>
<h:outputText value="Popup:"/>
<h:outputText value="#{calendarView.date2}">
<f:convertDateTime pattern="MM/dd/yyyy"/>
</h:outputText>
<h:outputText value="Button:"/>
<h:outputText value="#{calendarView.date3}">
<f:convertDateTime pattern="MM/dd/yyyy"/>
</h:outputText>
<h:outputText value="Event:"/>
<h:outputText value="#{calendarView.date4}">
<f:convertDateTime pattern="MM/dd/yyyy"/>
</h:outputText>
<h:outputText value="German:"/>
<h:outputText value="#{calendarView.date5}">
<f:convertDateTime pattern="yyyy-MMM-dd"/>
</h:outputText>
<h:outputText value="German (other Pattern):"/>
<h:outputText value="#{calendarView.date5}">
<f:convertDateTime pattern="dd.MM.yyyy"/>
</h:outputText>
<h:outputText value="Restricted:"/>
<h:outputText value="#{calendarView.date6}">
<f:convertDateTime pattern="MM/dd/yyyy"/>
</h:outputText>
<h:outputText value="Multiple:"/>
<h:outputText value="#{calendarView.date7}">
<f:convertDateTime pattern="MM/dd/yyyy"/>
</h:outputText>
<h:outputText value="Effect:"/>
<h:outputText value="#{calendarView.date8}">
<f:convertDateTime pattern="MM/dd/yyyy"/>
</h:outputText>
<h:outputText value="Mask:"/>
<h:outputText value="#{calendarView.date9}">
<f:convertDateTime pattern="MM/dd/yyyy"/>
</h:outputText>
<h:outputText value="Datetime:"/>
<h:outputText value="#{calendarView.date10}">
<f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss"/>
</h:outputText>
<h:outputText value="Datetime (German):"/>
<h:outputText value="#{calendarView.dateTimeDe}">
<f:convertDateTime pattern="dd.MM.yyyy HH:mm"/>
</h:outputText>
<h:outputText value="Time Only:"/>
<h:outputText value="#{calendarView.date11}">
<f:convertDateTime pattern="HH:mm"/>
</h:outputText>
</p:panelGrid>
</p:dialog>
</h:form>
</div>
package org.primefaces.showcase.view.input;
import jakarta.annotation.PostConstruct;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
import jakarta.validation.constraints.Future;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import io.quarkus.runtime.annotations.RegisterForReflection;
import org.primefaces.PrimeFaces;
import org.primefaces.event.SelectEvent;
@Named
@ViewScoped
@RegisterForReflection(serialization = true)
public class CalendarView implements Serializable {
private Date date;
private Date date1;
@Future
private Date date2;
private Date date3;
private Date date4;
private Date date5;
private Date date6;
private Date date7;
private Date date8;
private Date date9;
private Date dateDe;
@Future
private Date date10;
private Date date11;
private Date date12;
private Date date13;
private Date date14;
private Date date15;
private Date date16;
private Date date17;
private Date dateTimeDe;
private Date dateTimeMillis;
private List<Date> multi;
private List<Date> range;
private List<Date> invalidDates;
private List<Date> validDates;
private List<Integer> invalidDays;
private Date minDate;
private Date maxDate;
private Date minTime;
private Date maxTime;
private Date minDateTime;
private Date maxDateTime;
@PostConstruct
public void init() {
invalidDates = new ArrayList<>();
Date today = new Date();
invalidDates.add(today);
long oneDay = 24 * 60 * 60 * 1000;
for (int i = 0; i < 5; i++) {
invalidDates.add(new Date(invalidDates.get(i).getTime() + oneDay));
}
validDates = new ArrayList<>();
validDates.add(today);
for (int i = 0; i < 5; i++) {
validDates.add(new Date(validDates.get(i).getTime() + oneDay));
}
invalidDays = new ArrayList<>();
invalidDays.add(0);
/* the first day of week is disabled */
invalidDays.add(3);
minDate = new Date(today.getTime() - (365 * oneDay));
maxDate = new Date(today.getTime() + (365 * oneDay));
Calendar tmp = Calendar.getInstance();
tmp.set(Calendar.HOUR_OF_DAY, 9);
tmp.set(Calendar.MINUTE, 0);
tmp.set(Calendar.SECOND, 0);
tmp.set(Calendar.MILLISECOND, 0);
minTime = tmp.getTime();
tmp = Calendar.getInstance();
tmp.set(Calendar.HOUR_OF_DAY, 17);
tmp.set(Calendar.MINUTE, 0);
tmp.set(Calendar.SECOND, 0);
tmp.set(Calendar.MILLISECOND, 0);
maxTime = tmp.getTime();
minDateTime = new Date(today.getTime() - (7 * oneDay));
maxDateTime = new Date(today.getTime() + (7 * oneDay));
dateDe = GregorianCalendar.getInstance().getTime();
dateTimeDe = GregorianCalendar.getInstance().getTime();
dateTimeMillis = GregorianCalendar.getInstance().getTime();
}
public void onDateSelect(SelectEvent<Date> event) {
FacesContext facesContext = FacesContext.getCurrentInstance();
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Date Selected", format.format(event.getObject())));
}
public void click() {
PrimeFaces.current().ajax().update("form:display");
PrimeFaces.current().executeScript("PF('dlg').show()");
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Date getDate1() {
return date1;
}
public void setDate1(Date date1) {
this.date1 = date1;
}
public Date getDate2() {
return date2;
}
public void setDate2(Date date2) {
this.date2 = date2;
}
public Date getDate3() {
return date3;
}
public void setDate3(Date date3) {
this.date3 = date3;
}
public Date getDate4() {
return date4;
}
public void setDate4(Date date4) {
this.date4 = date4;
}
public Date getDate5() {
return date5;
}
public void setDate5(Date date5) {
this.date5 = date5;
}
public Date getDate6() {
return date6;
}
public void setDate6(Date date6) {
this.date6 = date6;
}
public Date getDate7() {
return date7;
}
public void setDate7(Date date7) {
this.date7 = date7;
}
public Date getDate8() {
return date8;
}
public void setDate8(Date date8) {
this.date8 = date8;
}
public Date getDate9() {
return date9;
}
public void setDate9(Date date9) {
this.date9 = date9;
}
public Date getDate10() {
return date10;
}
public void setDate10(Date date10) {
this.date10 = date10;
}
public Date getDate11() {
return date11;
}
public void setDate11(Date date11) {
this.date11 = date11;
}
public Date getDate12() {
return date12;
}
public void setDate12(Date date12) {
this.date12 = date12;
}
public Date getDate13() {
return date13;
}
public void setDate13(Date date13) {
this.date13 = date13;
}
public Date getDate14() {
return date14;
}
public void setDate14(Date date14) {
this.date14 = date14;
}
public Date getDate17() {
return date17;
}
public void setDate17(Date date17) {
this.date17 = date17;
}
public List<Date> getMulti() {
return multi;
}
public void setMulti(List<Date> multi) {
this.multi = multi;
}
public List<Date> getRange() {
return range;
}
public void setRange(List<Date> range) {
this.range = range;
}
public List<Date> getInvalidDates() {
return invalidDates;
}
public void setInvalidDates(List<Date> invalidDates) {
this.invalidDates = invalidDates;
}
public List<Date> getValidDates() {
return validDates;
}
public void setValidDates(List<Date> validDates) {
this.validDates = validDates;
}
public List<Integer> getInvalidDays() {
return invalidDays;
}
public void setInvalidDays(List<Integer> invalidDays) {
this.invalidDays = invalidDays;
}
public Date getMinDate() {
return minDate;
}
public void setMinDate(Date minDate) {
this.minDate = minDate;
}
public Date getMaxDate() {
return maxDate;
}
public void setMaxDate(Date maxDate) {
this.maxDate = maxDate;
}
public Date getDateTimeDe() {
return dateTimeDe;
}
public void setDateTimeDe(Date dateTimeDe) {
this.dateTimeDe = dateTimeDe;
}
public Date getDateDe() {
return dateDe;
}
public void setDateDe(Date dateDe) {
this.dateDe = dateDe;
}
public Date getDateTimeMillis() {
return dateTimeMillis;
}
public void setDateTimeMillis(Date dateTimeMillis) {
this.dateTimeMillis = dateTimeMillis;
}
public Date getDate15() {
return date15;
}
public void setDate15(Date date15) {
this.date15 = date15;
}
public Date getMinTime() {
return minTime;
}
public void setMinTime(Date minTime) {
this.minTime = minTime;
}
public Date getMaxTime() {
return maxTime;
}
public void setMaxTime(Date maxTime) {
this.maxTime = maxTime;
}
public Date getDate16() {
return date16;
}
public void setDate16(Date date16) {
this.date16 = date16;
}
public Date getMinDateTime() {
return minDateTime;
}
public void setMinDateTime(Date minDateTime) {
this.minDateTime = minDateTime;
}
public Date getMaxDateTime() {
return maxDateTime;
}
public void setMaxDateTime(Date maxDateTime) {
this.maxDateTime = maxDateTime;
}
}