繁体   English   中英

PrimeFaces 3.0 - 需要修复或解决方法<p:calendar> “增加 6 年”缺陷</p:calendar>

[英]PrimeFaces 3.0 - Need fix or workaround for <p:calendar> 'add 6 years' defect

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

报告为 PrimeFaces 问题跟踪器中的缺陷。 添加星号为 PrimeFaces 开发团队投票以解决此问题:链接到他们的问题跟踪器中的缺陷

PrimeFaces支持论坛中进行了讨论。

PrimeFaces 3.0-M3-SNAPSHOT 中依然存在

问题:

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

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

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

与最初为空的托管 bean 属性相关联 - 显示正常

与最初为空的托管 bean 属性相关联 - 可以正常打开

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

与最初填充的托管 bean 属性相关联 - 显示正常

与最初填充的托管 bean 属性相关联 - 打开不正常

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

ddHHmm'Z'MMMyy

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

与最初的空值相关联并具有自定义模式 - 无法打开控件!

问题:是否有人对这些<p:calendar>问题有任何解决方法?

更新 - 源代码:

包装<p:calendar>的复合组件:

<?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)");
    }

}

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM