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