1 Reply Latest reply: May 18, 2010 5:17 PM by Stefan Tausendpfund RSS

Problem developing Upload file portlet

Jorge Ferreyra Newbie

Hello, and thanks for your answers.

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


        <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}" />


and MyBean.java:


import java.io.*;
import org.apache.myfaces.custom.fileupload.UploadedFile;

public class MyBean {

    private UploadedFile upFile;

     //setters, getters

    public String upload(){
        try {
            InputStream stream = upFile.getInputStream();
            long size = upFile.getSize();
            byte[] buffer = new byte[(int) size];
            stream.read(buffer, 0, (int) size);
            System.out.println("File Upload Successful.");
        } catch (Exception ioe) {
            System.out.println("File Upload Unsuccessful.");
        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?