2 Replies Latest reply on May 17, 2009 7:43 PM by John Ament

    rich file upload not working? or something else?

    John Ament Master

      so mind you, i've only been playing a bit with webbeans.  wanted to try out a file uploader.  very similar to stuff i've done w/ seam; defined the view as:



           <ui:composition template="template.xhtml">
                     <ui:define name="pageTitle">Title</ui:define>
                     <ui:define name="pageHeader">Image Uploader</ui:define>
                     <ui:define name="body">
                          <form jsfc="h:form" id="Form">
                               <rich:fileUpload acceptedTypes="tif" allowFlash="true" maxFilesQuantity="100"
                               fileUploadListener="#{uploader.onUpload}">
                               </rich:fileUpload>
                          </form>
                     </ui:define>
           </ui:composition>



      and the following web bean is not being found (resolves to null).  maybe because it's so late I'm just not thinking right...



      @Named("uploader") @RequestScoped
      public class FileUploadListener {
           public void onUpload(UploadEvent e) {
                List<UploadItem> items = e.getUploadItems();
                for(UploadItem item : items) onItem(item);
           }
           private void onItem(UploadItem item) {
                File src = item.getFile();
                String fileName = item.getFileName();
                int size = item.getFileSize();
                File f = new File("/images");
                File img = new File(f,fileName);
                try {
                     img.createNewFile();
                } catch (IOException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                }
                src.renameTo(img);
           }
      }