5 Replies Latest reply on Mar 11, 2011 7:14 AM by thomas1980m

    file upload does not work - need help

    thomas1980m

      hello


      i implemented the following file upload in seam, but the values in the UploadedFile are always null. can anyone help me please?


      components.xml:


      <web:multipart-filter create-temp-files="true" max-request-size="100000000" url-pattern="*.seam" /> 




      web.xml:





      <filter>
      <filter-name>Seam Multipart Filter</filter-name>
      <filter-class>org.jboss.seam.web.MultipartFilter</filter-class>
      </filter>
      
      <filter-mapping>
      <filter-name>Seam Multipart Filter</filter-name>
      <url-pattern>*.seam</url-pattern>
      </filter-mapping>




      UploadedFile.java:




      @Name("uploadedFile")
      public class UploadedFile {
      
              private InputStream uploadedFileData;
              private String fileName;
      
              public String getFileName() {
                      System.out.println("getFileName:" + this.fileName);
                      return this.fileName;
              }
      
              public void setFileName(String fileName) {
                      System.out.println("setFileName:" + this.fileName);
                      this.fileName = fileName;
              }
      
              public InputStream getUploadedFileData() {
                      System.out.println("getuploadedFileData:" + this.uploadedFileData);
                      return this.uploadedFileData;
              }
      
              public void setUploadedFileData(InputStream uploadedFileData) {
                      System.out.println("setuploadedFileData:" + uploadedFileData);
                      this.uploadedFileData = uploadedFileData;
              }
      
              public void parse() throws Exception {
                      System.out.println("parse:" + this.fileName);
      
                      System.out.println("parse2:" + getUploadedFileData());
                      if (uploadedFileData != null) {
                              System.out.println("size = " + uploadedFileData);
                      } else {
                              System.out.println("file is null");
                      }
              }



      and on the html page i implemented:




      <h:form enctype="multipart/form-data">
      <s:validateAll>
      <table class="filter">
      <tbody>
      <tr>
      <td>#{messages['ExeclImport.SelectFile']}</td>
      <td>
      <s:fileUpload data="#{uploadedFile.uploadedFileData}" fileName="#{uploadedFile.fileName}" />
      </td>
      <td>
      <h:commandButton id="upload" action="#{uploadedFile.parse}" value="#{messages['Button.Upload']}" />
      </td>
      </tr>                            
      </tbody>
      </table>
      </s:validateAll>            
      </h:form>



        • 1. Re: file upload does not work - need help
          xsalefter.xsalefter.yahoo.com

          Well, your


          uploadedFile#parse()



          method do not do anything except print it to the console ;). However, some google result may help you out from this problem.


          HTH.

          • 2. Re: file upload does not work - need help
            thomas1980m

            hello


            yes i know, but the printed values are null. so nothing is sent to the server ... and i don't know why. getUploadedFileData() should print the sended data but it is null.


            • 3. Re: file upload does not work - need help
              xsalefter.xsalefter.yahoo.com

              Ups.. So sorry. My bad. I didn't read your question correctly :).


              Btw, Do you have try to remove/change this line:



              <filter>
              <filter-name>Seam Multipart Filter</filter-name>
              <filter-class>org.jboss.seam.web.MultipartFilter</filter-class>
              </filter>
              
              <filter-mapping>
              <filter-name>Seam Multipart Filter</filter-name>
              <url-pattern>*.seam</url-pattern>
              </filter-mapping>
              


              AFAIK you don't need to did it, as explained in documentation .


              HTH.

              • 4. Re: file upload does not work - need help
                thomas1980m

                yes i have already removed theses entries but still null.


                i also tried to set create-temp-files false - still null


                if i try s:token in the form, i get invalid form signature.


                i'm using tomcat as server and not jboss ...

                • 5. Re: file upload does not work - need help
                  thomas1980m

                  Thomas Mayer wrote on Mar 11, 2011 06:46:


                  yes i have already removed theses entries but still null.

                  i also tried to set create-temp-files false - still null

                  if i try s:token in the form, i get invalid form signature.

                  i'm using tomcat as server and not jboss ...


                  org.jboss.seam.ui.UnauthorizedCommandException: viewId: /trading/execl-import.html - Form signature invalid
                          at org.jboss.seam.ui.renderkit.TokenRendererBase.doDecode(TokenRendererBase.java:110)
                          at org.jboss.seam.ui.util.cdk.RendererBase.decode(RendererBase.java:59)
                          at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:791)
                          at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1048)
                          at javax.faces.component.UIForm.processDecodes(UIForm.java:212)
                          at javax.faces.component.UIForm.processDecodes(UIForm.java:212)
                          at org.ajax4jsf.component.AjaxViewRoot$1.invokeContextCallback(AjaxViewRoot.java:400)
                          at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:240)
                          at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:417)
                          at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:74)
                          at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
                          at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
                          at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
                          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)