I have a simple xhtml file using rich:fileupload component. fileUploadListener specified doesn't work with CDI class i.e. with @Named and @javax.enterprise.context.SessionScoped. But same class works by using @ManagedBean and @javax.faces.bean.SessionScoped annotation. Ofcourse, CDI class is in my EJB project and ManagedBean class is Web project.
I don't want to use @ManagedBean as all my JSF beans are using @Named and I want to use fileUpload in one of the existing classes.
Any help will be appreciated. Below is the code:
----------------from XHTML file --------------------
<h:form>
<rich:fileUpload fileUploadListener="#{testupload.listener}" id="fileUpload"
maxFilesQuantity="5"
ontyperejected="alert('Only JPG, GIF, PNG and BMP files are accepted');"
acceptedTypes="JPG,jpg"/>
</h:form>
----------------- BELOW CODE DOESN"T WORK--------------------
@Named("testupload")
@javax.enterprise.context.SessionScoped
public class TestFileUpload implements Serializable
{
public void listener(FileUploadEvent event) throws Exception
{
System.out.println("file has been uploaded..." + event.getUploadedFile().getName() +
" file size " + event.getUploadedFile().getSize());
}
}
----------------- THIS ONE WORKS--------------------
@ManagedBean(name="testupload")
@javax.faces.bean.SessionScoped
public class TestFileUpload implements Serializable
{
public void listener(FileUploadEvent event) throws Exception
{
System.out.println("file has been uploaded..." + event.getUploadedFile().getName() +
" file size " + event.getUploadedFile().getSize());
}
}
a related problem.