WELD-001303范围类型javax.faces.view.ViewScoped没有活动的上下文

时间:2013-06-18 10:30:47

标签: jsf cdi view-scope

我已将javax.enterprise.context.SessionScoped切换为javax.faces.view.ViewScoped 升级面2.1至2.2,以便能够使用ViewScoped进行CDI注射。

切换到ViewScoped后,我开始收到此错误,但我无法弄清楚原因!你认为这里有什么问题吗?

Glassfish 3.1.2,Primefaces 3.4.2,JSF 2.2

org.jboss.weld.context.ContextNotActiveException:WELD-001303范围类型javax.faces.view.ViewScoped

没有活动的上下文

按钮打开页面:      

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;
    }
}

1 个答案:

答案 0 :(得分:3)

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