1 Reply Latest reply on Apr 12, 2006 4:42 AM by Uhyon Chung

    to upload a file with seam - do i extend SeamServletFilter?

    tom soucy Newbie

      I'm trying to upload a file. I had done this with JSF and when I try to migrate the application using seam i'm having assorted problems. As I try to discover the root cause I'm thinking that someone may have already achieved a nice way to upload using seam. Does anyone have a pattern of code to to this? My requirement is to have user browse for the file locally and then submit the form to upload the file to the server. i assume that i'd use a filter (as was done with JSF). I assume use of apache commons library for framework.

      thx

        • 1. Re: to upload a file with seam - do i extend SeamServletFilt
          Uhyon Chung Newbie

          You might want to check out

          http://www.onjava.com/pub/a/onjava/2005/07/13/jsfupload.html

          I just recently tried file uploading, and it worked fine. The only issue you'll come across is with classloading issues.
          If you're using tomahawk, then you have to either
          1) put the tomahawk.jar in jsf-libs (under tomcatXXX.sar)
          2) put tomhawk.jar in ear and reference it using Class-Path: in the MANIFEST file (of EJB jar)
          3) put it in WEB-INF/lib and create a separate bean in the web portion (which means the code that goes under WEB-INF/classes or WEB-INF/lib).

          Main reason is that the EJB code cannot (and probably should not) access the org.apache.myfaces.custom.fileupload.UploadedFile unless you specifically make it visible.

          FYI :

          <%@ 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>
          
           <h:form id="MyForm" enctype="multipart/form-data" >
           ...
           <x:inputFileUpload id="myFileId"
           value="#{myBean.myFile}"
           storage="file"
           required="true"/>
           ...
           </h:form>
          
          </f:view>
          
          
          import org.apache.myfaces.custom.fileupload.UploadedFile;
          ...
          public class MyBean {
           private UploadedFile myFile;
          
           public UploadedFile getMyFile() {
           return myFile;
           }
          
           public void setMyFile(UploadedFile myFile) {
           this.myFile = myFile;
           }
           ...
          }