【问题标题】:Exception trying to poll with PrimeFaces尝试使用 PrimeFaces 轮询的异常
【发布时间】:2021-11-21 19:41:25
【问题描述】:

我在尝试使用 PrimeFaces 进行轮询时遇到异常。我正在使用来自Primefaces fileUpload and session timout 的解决方案#1。

javax.faces.FacesException: 类 java.lang.Long 不支持作为 p:poll 的“间隔”

<p:fileUpload id="fileUploadControl" oncomplete="PF('xmlUploadDialog').hide()"
              listener="#{xmlUploadBean.handleFileUpload}" mode="advanced"
              allowTypes="/(\.|\/)(xml|zip)$/" update=":mainForm:scriptTableId"
              multiple="true" />
<p:poll interval="#{session.maxInactiveInterval - 10}" async="true" />

【问题讨论】:

    标签: jsf primefaces el


    【解决方案1】:

    在 PrimeFaces 10 中,属性 interval 不采用 Long,它可以采用 IntegerDuration

    查看代码:

            Object interval = poll.getInterval();
    
            int convertedInterval;
            if (interval instanceof Integer) {
                convertedInterval = (Integer) interval;
            }
            else if (interval instanceof Duration) {
                convertedInterval = (int) ((Duration) interval).getSeconds();
            }
            else if (interval instanceof String) {
                try {
                    convertedInterval = Integer.parseInt((String) interval);
                }
                catch (NumberFormatException e) {
                    throw new FacesException(interval + " is not a valid integer for \"interval\" for p:poll", e);
                }
            }
            else {
                throw new FacesException(interval.getClass() + " is not supported as \"interval\" for p:poll");
            }
    

    PrimeFaces 11 添加了对Long 的支持。

    猜你喜欢
    • 2014-08-15
    • 2018-04-30
    • 1970-01-01
    • 2019-08-02
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    • 1970-01-01
    • 2012-09-10
    相关资源
    最近更新 更多