I'm doing file upload and have implemented it the way it is suggested here:
http://wiki.apache.org/myfaces/Setup_For_File_Uploads
On the view I have this code to do upload:
<t:inputFileUpload storage="file" immediate="true"> <f:valueChangeListener type="com.myorg.foo.UploadListener" /> </t:inputFileUpload>
The listener that processes the upload is something like : public class UploadListener implements ValueChangeListener { public void processValueChange(ValueChangeEvent event) throws AbortProcessingException { // Upload and do something with uploadedFile } }
@Stateless @Name("uploadListener") public class UploadListener implements ValueChangeListener { @Logger private Log log; @PersistenceContext private EntityManager em; @In User user; public void processValueChange(ValueChangeEvent event) throws AbortProcessingException { if (log == null) System.out.println("Log is null !!" ); if (em == null) System.out.println("EntityManager is null !!" ); if (user == null) System.out.println("User is null !!" ); // Upload and do something with uploadedFile } }