WELD-001303 No active contexts for scope type javax.faces.view.ViewScoped

独自空忆成欢 提交于 2019-12-21 06:29:55

问题


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

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 No active contexts for scope type javax.faces.view.ViewScoped

The button opens the page:

The jsf page;

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

Controller;

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:


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



来源:https://stackoverflow.com/questions/17166626/weld-001303-no-active-contexts-for-scope-type-javax-faces-view-viewscoped

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!