手机上的Primefaces时间轴NumberFormatException(NaN)

时间:2019-02-18 15:58:56

标签: jsf primefaces

我正在使用素数(6.1)时间轴,并且在双击(触摸)任何组行以添加新事件时,都在移动设备(Android中为Chrome)上获得NumberFormatException (NaN)。 / p>

在台式机中它可以正常工作,而在Firefox for Android中也可以。

<h:head>
    <f:metadata>
        <f:event type="preRenderView"
            listener="#{bookingController.preRenderView}" />
    </f:metadata>
</h:head>
<h:body>
    <h:form id="frmLT">
        <!-- Timeline -->
        <p:timeline id="timeline" value="#{bookingManagedBean.timeLineModel}"
            widgetVar="wvTimeline" editable="true" eventMargin="10"
            eventMarginAxis="0" start="#{bookingManagedBean.startDate}"
            end="#{bookingManagedBean.endDate}" showNavigation="#{true}"
            showButtonNew="true" axisOnTop="true" stackEvents="false">
            <p:ajax event="add" listener="#{bookingController.addEvent}"
                update="bookingForm timeline" />
        </p:timeline>
    </h:form>

    <h:form id="bookingForm">
        <h:panelGroup layout="block">
            <p:outputLabel value="Selected date:" for="selectedDate" />
            <p:calendar id="selectedDate" readonlyInput="true"
                value="#{bookingManagedBean.selectedEvent.startDate}">
            </p:calendar>
        </h:panelGroup>
    </h:form>
</h:body>
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.timeline.TimelineAddEvent;
import org.primefaces.model.timeline.TimelineEvent;

@ManagedBean(name = "bookingController")
@RequestScoped
public class BookingController implements Serializable {

    private static final long serialVersionUID = 1L;
    @ManagedProperty("#{bookingManagedBean}")
    private BookingManagedBean bookingManagedBean;

    public BookingController() {
    }

    public void preRenderView() {
        if (!FacesContext.getCurrentInstance().isPostback()) {

            bookingManagedBean.setStartDate(new Date());

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(bookingManagedBean.getStartDate());
            calendar.add(Calendar.DATE, 7);
            bookingManagedBean.setEndDate(calendar.getTime());

            TimelineEvent demoEvent = new TimelineEvent("Demo Event", new Date(), false, "Demo Group");
            bookingManagedBean.getTimeLineModel().add(demoEvent);
        }
    }

    public void addEvent(TimelineAddEvent addEvent) {
        bookingManagedBean
            .setSelectedEvent(new TimelineEvent("New Event", addEvent.getStartDate(), false, addEvent.getGroup()));
        bookingManagedBean.getTimeLineModel().add(bookingManagedBean.getSelectedEvent());
    }

    // Getters and setters
}
import java.io.Serializable;
import java.util.Date;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.primefaces.model.timeline.TimelineEvent;
import org.primefaces.model.timeline.TimelineModel;

@ManagedBean(name = "bookingManagedBean")
@ViewScoped
public class BookingManagedBean implements Serializable {

    private static final long serialVersionUID = 1L;

    private Date startDate;
    private Date endDate;
    private TimelineModel timeLineModel;

    private TimelineEvent selectedEvent;

    @PostConstruct
    public void init() {
        this.timeLineModel = new TimelineModel();
    }

    public BookingManagedBean() {
    }

    // Getters and setters
}

捕获的日期应该触发ajax“ add”事件,但是却给了我上述异常。

feb 19, 2019 5:54:57 PM com.sun.faces.context.PartialViewContextImpl processPartial
INFORMACIÓN: java.lang.NumberFormatException: For input string: "NaN"
java.lang.NumberFormatException: For input string: "NaN"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Long.parseLong(Long.java:589)
    at java.lang.Long.valueOf(Long.java:803)
    at org.primefaces.util.DateUtils.toUtcDate(DateUtils.java:29)
    at org.primefaces.component.timeline.Timeline.queueEvent(Timeline.java:558)
    at org.primefaces.behavior.ajax.AjaxBehaviorRenderer.decode(AjaxBehaviorRenderer.java:47)
    at javax.faces.component.behavior.ClientBehaviorBase.decode(ClientBehaviorBase.java:132)
    at org.primefaces.renderkit.CoreRenderer.decodeBehaviors(CoreRenderer.java:559)
    at org.primefaces.component.timeline.TimelineRenderer.decode(TimelineRenderer.java:41)

0 个答案:

没有答案