📅  最后修改于: 2021-01-08 04:06:05             🧑  作者: Mango
它是用于选择日期的输入组件。 组件用于在JSF应用程序中创建日历。它包括各种功能,例如:显示模式,分页,本地化,ajax选择等。
日历的值应为java.util.Date。
下表包含“日历”组件的属性。
Attribute | Default value | Return type | Description |
---|---|---|---|
id | null | String | It is an unique identifier of the component. |
rendered | true | Boolean | It takes boolean value to specify the rendering of the component. |
value | null | java.util.Date | It is used to set value of the component. |
converter | null | Converter/String | It takes an expression or a literal text that defines a converter for the component. |
required | false | Boolean | It is used to make component as required. |
mindate | false | Date or String |
It is used to set calendar’s minimum visible date. |
maxdate | null | Date or String |
It is used to set calendar’s maximum visible date. |
pages | 1 | Integer | It enables multiple page rendering. |
mode | popup | String | It is used to define how the calendar will be displayed. |
pattern | MM/dd/yyyy | String | It is used to set DateFormat pattern for localization. |
timeZone | null | Time Zone |
It is used to specify the timezone used for date conversion. |
showWeek | false | Boolean | It is used to display the week number next to each week. |
disabledWeekends | false | Boolean | It disables weekend columns. |
showOtherMonths | false | Boolean | It displays days belonging to other months. |
selectOtherMonths | false | Boolean | It enables selection of days belonging to other months. |
yearRange | null | String | It is used to set year range. |
timeOnly | false | Boolean | It shows only timepicker without date. |
下表包含结构样式类。
Style Class | Applies |
---|---|
.ui-datepicker | It is used for main container. |
.ui-datepicker-header | It is used for header container. |
.ui-datepicker-prev | It is used for previous month navigator. |
.ui-datepicker-next | It is used for next month navigator. |
.ui-datepicker-title | It is used for title. |
.ui-datepicker-month | It is used for month display. |
.ui-datepicker-table | It is used for date table. |
.ui-datepicker-week-end | This class is used for label of weekends. |
.ui-datepicker-other-month | Class for dates belonging to other months. |
.ui-datepicker td | It is used for each cell date. |
.ui-datepicker-buttonpane | This is button panel class. |
.ui-datepicker-current | This class is used for today button. |
.ui-datepicker-close | It is used to display close button. |
在下面的示例中,我们正在实现组件。本示例包含以下文件。
// calendar.xhtml
Calendar Example
// Calendar.java
package com.javatpoint;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import org.primefaces.context.RequestContext;
import org.primefaces.event.SelectEvent;
@ManagedBean
public class Calendar {
private Date date;
public void onDateSelect(SelectEvent 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() {
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.update("form:display");
requestContext.execute("PF('dlg').show()");
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
运行JSF文件后,它将产生以下输出。
输出:
当我们在下面检查时,它显示消息。