Primefaces日历只有月份和年份选择不发送到bean

时间:2014-09-22 06:52:26

标签: primefaces calendar

我使用p:calendar只选择月份和年份。日期没有显示。但是我的选择不是去了managedBean.Here是代码;

<h:panelGroup id="editClusterStartDatePanel"
    class="datePickerYearAndMonth">
    <p:calendar id="editClusterStartDate"
        value="#{defineCommissionClusterPaymentBean.selectedClusterDate}"
        navigator="true" required="true"
        locale="#{languageBean.languageCode}" mode="inline" />
</h:panelGroup>

enter image description here

selectedClusterDate值每次都设置相同的日期。如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

<p:calendar id="editClusterStartDate"
        value="#{defineCommissionClusterPaymentBean.selectedClusterDate}"
        navigator="true" required="true"
        locale="#{languageBean.languageCode}" mode="inline"
        widgetVar="myCalendar">
                <p:ajax event="viewChange" onstart="
                                var mc=PF('myCalendar');
                                var crtDate=new Date(cfg.ext.params[1].value,cfg.ext.params[0].value-1,1,0,0,0);
                                /* see calendar.js, function bindDateSelectListener*/
                                var crtDateAsS=$.datepicker.formatDate(mc.cfg.dateFormat,crtDate);
                                mc.input.val(crtDateAsS);
                                return false;" />               
</p:calendar>

答案 1 :(得分:0)

调用onDateSelect而不是selectClusterDate或自定义backbean。

public void onDateSelect(SelectEvent event) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    SimpleDateFormat format = new SimpleDateFormat("MM/yyyy");
    format.format(event.getObject());
     //...
}