Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 无法解析PrimeFaces 4.0中的常量.REQUEST\u CONTEXT\u ATTR_Jsf_Primefaces - Fatal编程技术网

Jsf 无法解析PrimeFaces 4.0中的常量.REQUEST\u CONTEXT\u ATTR

Jsf 无法解析PrimeFaces 4.0中的常量.REQUEST\u CONTEXT\u ATTR,jsf,primefaces,Jsf,Primefaces,我需要更新GUI。它正在显示计时器。计时器工作正常。但包含计时器的页面或组件必须始终更新。然后我可以显示实时计时器。 所以我需要更新组件。但是RequestContext.getCurrentInstance()正在指向NullPointerException。我在下面找了找 ((RequestContext) FacesContext.getCurrentInstance().getAttributes().get(Constants.REQUEST_CONTEXT_ATTR);) 但是常量

我需要更新GUI。它正在显示计时器。计时器工作正常。但包含计时器的页面或组件必须始终更新。然后我可以显示实时计时器。 所以我需要更新组件。但是
RequestContext.getCurrentInstance()
正在指向
NullPointerException
。我在下面找了找

((RequestContext) FacesContext.getCurrentInstance().getAttributes().get(Constants.REQUEST_CONTEXT_ATTR);)

但是
常量。请求\u上下文\u属性
未解析。另一方面,我使用的是PrimeFaces4.0JSF2.0,将请求上下文属性涂成红色。我该如何决定?请建议我。

我怀疑您的代码中一定发生了奇怪的事情,例如,您的更新逻辑没有在faces servlet后面运行

如果您希望获取对正在进行的传入JSF请求处于活动状态的primefaces RequestContext实例,则可以使用RequestContext.getCurrentInstance()作为正确的API

如果您在那里得到一个NullPointer异常,它将显示为FacesContext没有使用primefaces中的RequestContext进行丰富

我认为这不应该发生。您应该交叉检查正在使用的Primefaces版本与正在运行的容器的兼容性。 primefaces 3.5适合JEE6,primefaces 4.0我不知道

Primefaces 6.0适用于JEE7等

如果您执行FacesCOntext.getCurrentInstance()之类的操作,您会爆炸吗? 如果是这样的话,这将表明您正在尝试执行更新逻辑,而不会使线程上下文的faces上下文处于活动状态。 例如,您无法从Mdb访问faces上下文。 或计时器轮询()。在那里要小心

最后,我相信你发布的常数已经从素数脸的常数中去掉了

他们已经将其封装到RequestContext对象本身中

下面是我现在正在查看的primefaces 6.0代码片段:

/*
 * Copyright 2009-2014 PrimeTek.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.primefaces.context;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.primefaces.component.api.AutoUpdatable;
import org.primefaces.util.AjaxRequestBuilder;
import org.primefaces.util.CSVBuilder;
import org.primefaces.util.StringEncrypter;
import org.primefaces.util.WidgetBuilder;

/**
 * A RequestContext is a helper class consisting of several utilities.
 * RequestContext is thread-safe and scope is same as FacesContext.
 * Current instance can be retrieved as;
 * <blockquote>
 *  RequestContext.getCurrentInstance();
 * </blockquote>
 */
public abstract class RequestContext {

    private static final ThreadLocal<RequestContext> INSTANCE = new ThreadLocal<RequestContext>();

    public static final String INSTANCE_KEY = RequestContext.class.getName();

    public static RequestContext getCurrentInstance() {

        RequestContext context = INSTANCE.get();

        // #6503 - it's valid that a FacesContext can be released during the request
        // Our PrimeFacesContext therefore will only release our ThreadLocal cache
        // The RequestContext will be destroyed automatically if the FacesContext and it's attributes will be destroyed
        if (context == null) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            if (facesContext != null && !facesContext.isReleased()) {
                context = (RequestContext) facesContext.getAttributes().get(INSTANCE_KEY);
                if (context != null) {
                    INSTANCE.set(context);
                }
            }
        }

        return INSTANCE.get();
    }
问题不在于使用什么常量,而在于getCurrentInstance()为什么会中断。 这通常表示JSFAPI没有在faces请求后面使用


Kind regads.

如果我没记错的话,
org.primefaces.util.Constants.REQUEST\u CONTEXT\u ATTR
自primefaces 3.5发布以来一直保留着,并且从primefaces 4.0开始就被删除了。所以我需要做什么来感谢一个广泛的答案,但我个人会问
FacesContext.getCurrentInstance()
是否有效。据我们所知,OP试图在jsf请求之外访问它,我同意,在旧版本6.0中,使用RequestContext将有一个NPEHi。但我问过是否可以获得FacesContext。引用上面的帖子:“如果你做了像FacesCOntext.getCurrentInstance()这样的事情,你会爆炸吗?…”Isorry;-)错过了那部分
facesContext.getAttributes().get(INSTANCE_KEY)