2

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;
    }
}
Pinchy
  • 1,506
  • 8
  • 28
  • 49
  • 1
    I have not looked at the source for JSF 2.2, so I have no idea how they've done the scope, but it could be something you're missing manually updating JSF in Glassfish. Have you tried GlassFish 4? – LightGuard Jun 18 '13 at 16:21
  • 1
    I would be extremely surprised if this worked. As far as I Know, JSF 2.2 requires additional integration w/ Weld to work. – John Ament Jun 18 '13 at 16:39
  • @LightGuard You are right, I have installed GlassFish 4 and it works with no WELD-001303 exception. Thanks for suggesting it. Maybe you should answer the question I will accept it as an answer! Cheers – Pinchy Jun 19 '13 at 10:31
  • @JohnAment Thanks John yes, need to change faces-config.xml too. It's already done as well. – Pinchy Jun 19 '13 at 10:33
  • I'm getting the same exception with Tomcat 8. I installed CDI with these instructions: http://balusc.blogspot.fi/2013/10/how-to-install-cdi-in-tomcat.html. From user's point of view everything seems to work fine. – Panu Haaramo Jun 07 '15 at 15:02

1 Answers1

4

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

LightGuard
  • 5,298
  • 19
  • 19