当showTime设置为true时,PrimeFaces 7.0 DatePicker引发JS TypeError

问题描述 投票:2回答:1

我正在像这样在我的.xhtml文件中使用PrimeFaces datePicker组件

<p:datePicker id="src_time"
    value="#{flightDetailController.flight.UTCsource}"
    pattern="dd.MM.yyyy" inline="true" />

这个flightDetailController有一个Flight对象的getter和setter方法

public void setFlight(Flight flight) {
    this.flight = flight;
    doReloadFlight();
}

public void doReloadFlight() {
    this.flight = flightService.loadFlight(flight.getFlightId());
}

public Flight getFlight() 
{
    if (flight == null) {
        flight = new Flight();
    }
    return flight;
}

并且Flight对象具有Java.util.Date对象的getter和setter方法

public Date getUTCsource() {
    return UTCsource;
}

public void setUTCsource(Date uTCsource) {
    UTCsource = uTCsource;
}

如果运行此代码,则广告投放(先前设置的广告)将加载得很好,并且datePicker将显示对象的日期。但是,当我将属性showTime="True"添加到datePicker时,我的控制台中出现以下JS异常:

Cannot read property 'split' of undefined TypeError: Cannot read property 'split' of undefined at K.<computed>.<computed>.parseTime

我正在使用PrimeFaces 7.0,根据文档值应将其设置为java.util.Date对象,它只是通过设置showTime =“ True”声明启用timePicker功能,所以我不确定要去哪里错误。

谢谢。

jsf primefaces
1个回答
0
投票

我的解决方案是创建一个转换器,并将日期显示为字符串

@Dependent
@FacesConverter(value = "fechaHoraConverter", managed = true)
public class FechaHoraConverter implements Converter<Date>{

    private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm a");

    @Override
    public Date getAsObject(FacesContext context, UIComponent component, String fecha) {
        try {
            return sdf.parse(fecha);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Date fecha) {
        return sdf.format(fecha);
    }

}


<p:datePicker id="ven" value="#{tr.tarea.vencimiento}" required="true" showTime="true" appendTo="@(body)" showIcon="true" readonlyInput="true" pattern="dd/MM/yyyy" hourFormat="12"
                            converter="fechaHoraConverter"/>
© www.soinside.com 2019 - 2024. All rights reserved.