本文介绍了WELD-001303作用域类型javax.faces.view.ViewScoped没有活动上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经切换到javax.enterprise.context.SessionScoped到javax.faces.view.ViewScoped将Face 2.1从2.1升级到2.2,以便可以将ViewScoped与我的CDI注入配合使用.

I have switched to javax.enterprise.context.SessionScoped to javax.faces.view.ViewScopedUpgraded faces 2.1 to 2.2 to be able to use ViewScoped with my CDI injections.

切换到ViewScoped后,我开始出现此错误,我不知道为什么!您认为这里有问题吗?

After I switched to ViewScoped I have started getting this error and I can't figure out why! Do you think there is something wrong here?

Glassfish 3.1.2,Primefaces 3.4.2,JSF 2.2

org.jboss.weld.context.ContextNotActiveException:WELD-001303作用域类型javax.faces.view.ViewScoped没有活动上下文

org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.faces.view.ViewScoped

该按钮将打开页面:

The button opens the page:

jsf页面;

<h:form enctype="multipart/form-data">
    <p:fieldset legend="Create new feed" toggleable="true" collapsed="true" >
        <p:fileUpload fileUploadListener="#{adminHomeController.handleFileUpload}" style="margin-top: 20px;"
                      mode="advanced" 
                      update="messages"
                      sizeLimit="1000000" 
                      multiple="false" 
                      allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>
        <p:inputText label="Baslik" style="margin-top: 20px;" required="true" value="#{adminHomeController.newFieldset.legend}"  /> 
        <p:editor style="margin-top: 20px;"
                  value="#{adminHomeController.newFieldset.content}" />
        <p:commandButton style="margin-top: 20px;" value="#{msg['common.save']}" update="messages" icon="ui-icon-disk" actionListener="#{adminHomeController.saveFieldset()}"/>
    </p:fieldset>
    <p:growl id="messages" showDetail="true"/>
</h:form>

控制器;

import com.bg.entity.Fieldset;
import com.bg.service.Service;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.event.FileUploadEvent;

@Named
@ViewScoped
public class AdminHomeController implements Serializable{

    @Inject
    private Service service;
    private Fieldset newFieldset;

    public AdminHomeController() {
    }

    @PostConstruct
    public void init() {
        System.out.println("INIT");
        newFieldset = new Fieldset();
    }

    public void handleFileUpload(FileUploadEvent event) {
        System.out.println("HandleFileUpload");
        byte[] file = event.getFile().getContents();
        newFieldset.setData(file);
        FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

    public void saveFieldset() {
        System.out.println("SaveFieldset");
        service.create(newFieldset);
        FacesMessage msg = new FacesMessage("Succesful", newFieldset.getLegend() + " is saved.");
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

    /**
     * @return the newFieldset
     */
    public Fieldset getNewFieldset() {
        System.out.println("getNewFieldset");
        return newFieldset;
    }

    /**
     * @param newFieldset the newFieldset to set
     */
    public void setNewFieldset(Fieldset newFieldset) {
        System.out.println("setNewFieldset");
        this.newFieldset = newFieldset;
    }
}

推荐答案

JSF 2.2需要对CDI支持进行其他更改,应使用EE 7服务器.

JSF 2.2 requires additional changes for CDI support, an EE 7 server should be used.

这篇关于WELD-001303作用域类型javax.faces.view.ViewScoped没有活动上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 01:20