JSF - 使用SimpleDateFormat格式化<p:calendar> </p:calendar>

时间:2014-06-03 10:35:39

标签: jsf jsf-2 primefaces calendar

我在XHTML中有<p:calendar>代码

<p:calendar
                                                value="#{Bean.targetdate}"
                                                pattern="MM/dd/yyyy" size="10" navigator="true"
                                                rendered="#{Bean.editCmdActionflg == true}"
                                                onblur="fChkDate(this);">
                                                <f:convertDateTime type="date" pattern="MM/dd/yyyy" />


我的问题是当我提供无效日期,例如12/31/6666 <p:calendar>接受日期,我在支持bean中做了SOP,我得到Mon Dec 31 00:00:00 IST 6666日期我进入了。

我不应该允许用户输入无效日期,就像我在上面输入的日期一样。
我需要确保用户应该提供有效的日期。我该怎么做?

1 个答案:

答案 0 :(得分:0)

您可以使用yearRange属性来解决您的问题,例如 -

<p:calendar yearRange="c-125:c+50" value="#{Bean.targetdate}"  pattern="MM/dd/yyyy"  readonlyInput="true" size="10" navigator="true"
                                            rendered="#{Bean.editCmdActionflg == true}"
                                            onblur="fChkDate(this);"/>