1 Reply Latest reply on May 18, 2010 5:17 PM by stefan_tausendpfund

    Problem developing Upload file portlet

    jferreyram

      Hello, and thanks for your answers.

      I'm developing a portlet which will upload files to server. The code of home.xhtml file is:

       

      <f:view>
              <h:form id="welcomeForm" enctype="multipart/form-data">
                  <t:inputFileUpload id="fileupload" value="#{myBean.upFile}"    size="20" />
                  <h:commandButton value="Load the file" action="#{myBean.upload}" />
              </h:form>
       </f:view>

       

      and MyBean.java:

       

      import java.io.*;
      import org.apache.myfaces.custom.fileupload.UploadedFile;
      
      public class MyBean {
      
          private UploadedFile upFile;
      
           //setters, getters
      
          public String upload(){
              System.out.println("Uploading...");
              try {
                  InputStream stream = upFile.getInputStream();
                  long size = upFile.getSize();
                  byte[] buffer = new byte[(int) size];
                  stream.read(buffer, 0, (int) size);
                  stream.close();
                  System.out.println("File Upload Successful.");
              } catch (Exception ioe) {
                  System.out.println("File Upload Unsuccessful.");
                  System.out.println("//EXCEPTION");
                  ioe.printStackTrace();
              }
              return null;
          }
      
      }
      

       

      But, when I submit the form nothing happens, the upload method of the bean don't run. And, if I delete the enctype attribute of h:form, the upload method upload run, but if I do that, I couldn't upload the file to the server.

       

      Any body can help me, please?