You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Steffen Hankiewicz <ha...@sub.uni-goettingen.de> on 2005/02/28 13:23:24 UTC

file upload

Hi all,

once again I'm having a problem, that I cannot solve.

I'm trying to use the upload possibility of myfaces. In the
myfaces-example-application everything works fine. But when I use the
same code in my servlet it doesn't work.

For my tests I wrote a simple example-jsp. It works great, if I let it
run  in the myfaces-example-webapp. But in my own servlet it does not.
I  checked  everything  but  cannot  find  any  differece  between the
projects. If I change the enctype of the form the upload-method starts
- but the upload doesn't work. If I let the ectype stay in, the method
does  not  get  called.  Does  anyone  of  you have some idea, in wich
direction I could search further?

Thanks for your help and best regards,

Steffen

-------------------------------

<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>

<f:view>
        <head>
        </head>
        <body>

        <x:saveState value="#{fileUploadForm.name}" />

        <h:form enctype="multipart/form-data">

                <x:inputFileUpload id="fileupload" accept="image/*"
                        value="#{fileUploadForm.upFile}" storage="file"
                        styleClass="fileUploadInput" required="false" />
                <h:outputText value="text" />
                <h:inputText value="#{fileUploadForm.name}" />
                <h:commandButton value="upload start"
                        action="#{fileUploadForm.upload}" />
        </h:form>
    <h:graphicImage rendered="#{fileUploadForm.uploaded}" url="fileupload_showimg.jsf"/>

    </body>
</f:view>
</html>

-------------------------------

It uses the fileuploadform.java from the myfaces-example-webapp.

-------------------------------

package rusDML.Beans.Metadaten;

import java.io.IOException;
import org.apache.myfaces.custom.fileupload.UploadedFile;
import javax.faces.context.FacesContext;

/**
 * @author Manfred Geiler (latest modification by $Author: matzew $)
 * @version $Revision: 1.1 $ $Date: 2004/10/20 07:46:39 $
 */
public class FileUploadForm {
        private UploadedFile _upFile;
        private String _name = "";

        public UploadedFile getUpFile() {
                return _upFile;
        }

        public void setUpFile(UploadedFile upFile) {
                _upFile = upFile;
        }

        public String getName() {
                return _name;
        }

        public void setName(String name) {
                _name = name;
        }

        public String upload() throws IOException {
                FacesContext facesContext = FacesContext.getCurrentInstance();
                facesContext.getExternalContext().getApplicationMap().put("fileupload_bytes",
                facesContext.getExternalContext().getApplicationMap().put("fileupload_type",
                facesContext.getExternalContext().getApplicationMap().put("fileupload_name",
                return "ok";
        }

        public boolean isUploaded() {
                FacesContext facesContext = FacesContext.getCurrentInstance();
                return facesContext.getExternalContext().getApplicationMap().get("fileupload_bytes") != null;
        }

}
-------------------------------

So I changed my faces-config.xml by adding this:

-------------------------------
<managed-bean>
        <managed-bean-name>fileUploadForm</managed-bean-name>
        <managed-bean-class>rusDML.Beans.Metadaten.FileUploadForm</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
</managed-bean>
-------------------------------

And in my web.xml you can find my filter (which is the same as in the
myfaces-example):

-------------------------------
<!-- Extensions Filter -->
    <filter>
        <filter-name>extensionsFilter</filter-name>
        <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>
        <init-param>
            <param-name>uploadMaxFileSize</param-name>
            <param-value>100m</param-value>
            <description>Set the size limit for uploaded files.
                Format: 10 - 10 bytes
                        10k - 10 KB
                        10m - 10 MB
                        1g - 1 GB
            </description>
        </init-param>
        <init-param>
            <param-name>uploadThresholdSize</param-name>
            <param-value>100k</param-value>
            <description>Set the threshold size - files
                    below this limit are stored in memory, files above
                    this limit are stored on disk.

                Format: 10 - 10 bytes
                        10k - 10 KB
                        10m - 10 MB
                        1g - 1 GB
            </description>
        </init-param>
<!--        <init-param>
            <param-name>uploadRepositoryPath</param-name>
            <param-value>/temp</param-value>
            <description>Set the path where the intermediary files will be stored.
            </description>
        </init-param>-->
    </filter>
-------------------------------