【问题标题】:PrimeFaces 3.0 - Need fix or workaround for <p:calendar> 'add 6 years' defectPrimeFaces 3.0 - 需要修复或解决 <p:calendar> 'add 6 years' 缺陷
【发布时间】:2011-07-08 14:12:14
【问题描述】:

这个问题主要针对 PrimeFaces 开发团队,但也许其他人知道解决方法。我无法在 PrimeFaces 支持论坛上上传屏幕截图,但我可以在此处链接到我的问题。

报告为 PrimeFaces 问题跟踪器中的缺陷。添加一颗星,为 PrimeFaces 开发团队投票以解决此问题: link to defect in their issue tracker

在 PrimeFaces 支持论坛中讨论了 here

PrimeFaces 3.0-M3-SNAPSHOT 中仍然存在

问题:

我正在使用 PrimeFaces 3.0 &lt;p:calendar&gt; 控件来允许用户查看和编辑包含日期和时间的 Date 对象。 JavaScript 控件中似乎存在一些缺陷,导致它在 +6 年附近的某处给日期添加了一些奇怪的偏移量。

我已经设置了一些代码来演示这个问题。

在第一个 &lt;p:calendar&gt; 中,我使用了最初为 null 的托管 bean Date。控制没问题。它将打开并将初始值设置为当前日期,时/分/秒归零。我可以正常使用滑块设置小时、分钟和秒。

在第二个&lt;p:calendar&gt; 中,我使用了最初设置为new Date() 的托管bean Date。这将创建一个新的Date 对象,设置为当前服务器时间。控制是好的。尽管&lt;p:calendar&gt; 框中显示的日期/时间最初看起来是正确的,但在将来打开 JavaScript 选择器控件时,它将被修改为一些奇怪的值。在关闭选择器控件时,托管 bean 上的日期设置为奇怪的值。

另一个可能相关也可能不相关的问题是当我尝试使用自定义format 作为日期时:

ddHHmm'Z'MMMyy

我的客户在他们的域中使用这种格式,我需要以某种方式支持它。当我尝试单击该框时,&lt;p:calendar&gt; JavaScript 选择器甚至不会打开。关于模式的某些东西(在 Java SimpleDateFormat 中工作得很好)打破了它。 PrimeFaces 文档对此保持沉默。

问题:是否有人对这些&lt;p:calendar&gt; 问题有任何解决方法?

更新 - 源代码:

包装&lt;p:calendar&gt;的复合组件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:p="http://primefaces.prime.com.tr/ui"
        xmlns:composite="http://java.sun.com/jsf/composite">

    <composite:interface 
            displayName="calendar"
            shortDescription="Wrapper for a PrimeFaces p:calendar">
        <composite:attribute 
            name="dateValue" 
            displayName="dateValue"
            type="java.util.Date"
            required="true"
            shortDescription="EL expression that evaluates to a java.util.Date on a backing bean" />
        <composite:attribute 
            name="pattern" 
            displayName="pattern"
            type="java.lang.String"
            default="dd/MM/yyyy HH:mm:ss"
            shortDescription="Pattern used to format the underlying Date value. See SimpleDatePattern class documentation for pattern syntax. NOTE: p:calendar does not appear to support some complex patterns." />
        <composite:attribute
            name="ajaxRenderTargets"
            displayName="ajaxRenderTargets"
            type="java.lang.String"
            default="@none"
            shortDescription="Space-separated list of element ids that need to be rendered by Ajax when the calendar value changes. See f:ajax render attribute documentation." />
        <composite:attribute 
            name="tooltip" 
            displayName="tooltip"
            type="java.lang.String"
            default=""
            shortDescription="String to be used as the tooltip for this component" />
        <composite:attribute 
            name="label" 
            displayName="label"
            type="java.lang.String"
            default=""
            shortDescription="Label for this component. May be used in FacesMessages." />
        <composite:attribute 
            name="required" 
            displayName="required"
            type="java.lang.Boolean"
            default="false" />
    </composite:interface>

    <composite:implementation>
        <p:calendar
                id="pCalendarInsideCC"
                value="#{cc.attrs.dateValue}" 
                pattern="#{cc.attrs.pattern}"
                readOnlyInputText="true"
                showButtonPanel="false"
                popupIconOnly="false"
                showOn="focus"
                mode="popup"
                navigator="true"
                pages="1"
                showOtherMonths="true"
                selectOtherMonths="false"
                alt="#{cc.attrs.tooltip}"
                title="#{cc.attrs.tooltip}"
                required="#{cc.attrs.required}"
                label="#{cc.attrs.label}">
            <p:ajax 
                    event="valueChange"
                    update="#{cc.attrs.ajaxRenderTargets}" />
            <p:ajax 
                    event="change"
                    update="#{cc.attrs.ajaxRenderTargets}" />
        </p:calendar>
    </composite:implementation>
</html>

包含复合组件引用的页面:

<ui:composition template="/templates/primefaces/masterLayout.xhtml">

    <ui:param name="title" value="#{bundle.primeFacesCalendarCC_description}" />

    <ui:define name="content">
        <h:form id="contentForm">
            <h:panelGrid columns="3">
                <h:outputText
                        value="Initially empty Date reference on managed bean" />
                <sandbox:primeFacesCalendar
                        id="calendarCC1"
                        dateValue="#{primeFacesTestBean.userSubmittedDateTime}"
                        ajaxRenderTargets="messagesCalendar1 :ajaxRenderTargetsInTemplate"
                        required="true" />
                <p:messages 
                        id="messagesCalendar1" 
                        showSummary="false" 
                        showDetail="true" />

                <h:outputText
                        value="A 'new Date()' reference on managed bean" />
                <sandbox:primeFacesCalendar
                        id="calendarCC2"
                        dateValue="#{primeFacesTestBean.newDateInstance}"
                        ajaxRenderTargets="messagesCalendar2 :ajaxRenderTargetsInTemplate"
                        required="true" />
                <p:messages 
                        id="messagesCalendar2" 
                        showSummary="false" 
                        showDetail="true" />

                <h:outputText
                        value="Initially empty Date using ddHHmm'Z'MMMyy pattern" />
                <sandbox:primeFacesCalendar
                        id="calendarCC3"
                        dateValue="#{primeFacesTestBean.userSubmittedDateTime}"
                        ajaxRenderTargets="messagesCalendar2 :ajaxRenderTargetsInTemplate"
                        pattern="ddHHmm'Z'MMMyy"
                        required="true" />
                <p:messages 
                        id="messagesCalendar3" 
                        showSummary="false" 
                        showDetail="true" />

            </h:panelGrid>
        </h:form>
    </ui:define>

</ui:composition>

<ui:composition template="/templates/primefaces/masterLayout.xhtml">

    <ui:param name="title" value="#{bundle.primeFacesCalendarCC_description}" />

    <ui:define name="content">
        <h:form id="contentForm">
            <h:panelGrid columns="3">
                <h:outputText
                        value="Initially empty Date reference on managed bean" />
                <sandbox:primeFacesCalendar
                        id="calendarCC1"
                        dateValue="#{primeFacesTestBean.userSubmittedDateTime}"
                        ajaxRenderTargets="messagesCalendar1 :ajaxRenderTargetsInTemplate"
                        required="true" />
                <p:messages 
                        id="messagesCalendar1" 
                        showSummary="false" 
                        showDetail="true" />

                <h:outputText
                        value="A 'new Date()' reference on managed bean" />
                <sandbox:primeFacesCalendar
                        id="calendarCC2"
                        dateValue="#{primeFacesTestBean.newDateInstance}"
                        ajaxRenderTargets="messagesCalendar2 :ajaxRenderTargetsInTemplate"
                        required="true" />
                <p:messages 
                        id="messagesCalendar2" 
                        showSummary="false" 
                        showDetail="true" />

                <h:outputText
                        value="Initially empty Date using ddHHmm'Z'MMMyy pattern" />
                <sandbox:primeFacesCalendar
                        id="calendarCC3"
                        dateValue="#{primeFacesTestBean.userSubmittedDateTime}"
                        ajaxRenderTargets="messagesCalendar2 :ajaxRenderTargetsInTemplate"
                        pattern="ddHHmm'Z'MMMyy"
                        required="true" />
                <p:messages 
                        id="messagesCalendar3" 
                        showSummary="false" 
                        showDetail="true" />

            </h:panelGrid>
        </h:form>
    </ui:define>

</ui:composition>

托管 bean:

@ManagedBean(name="primeFacesTestBean")
@SessionScoped
public class PrimeFacesTestBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private Date userSubmittedDateTime = null;
    private Date newDateInstance = new Date();

    public void setUserSubmittedDateTime(Date userSubmittedDateTime) {
        this.userSubmittedDateTime = userSubmittedDateTime;
    }

    public Date getUserSubmittedDateTime() {
        return userSubmittedDateTime;
    }

    public void setNewDateInstance(Date newDateInstance) {
        this.newDateInstance = newDateInstance;
    }

    public Date getNewDateInstance() {
        return newDateInstance;
    }

    public void calendarValueChangeHandler(AjaxBehaviorEvent event) {
        //System.out.println("calendar value has been changed (Ajaxified)");
    }

}

【问题讨论】:

    标签: java jsf-2 calendar datepicker primefaces


    【解决方案1】:

    自 8 月 18 日起在 3.0-M3-SNAPSHOT 中修复:
    http://code.google.com/p/primefaces/issues/detail?id=2215

    使用 8 月 23 日的 3.0-M3-SNAPSHOT 确认它在我的 web 应用中正常工作。

    注意:此缺陷未涵盖自定义格式问题。我不确定这是否已解决或仍然存在问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-08
      • 2017-05-12
      • 2017-03-16
      • 1970-01-01
      • 1970-01-01
      • 2012-10-19
      相关资源
      最近更新 更多