2 Replies Latest reply on Nov 23, 2008 10:07 PM by kirkor.grzegorz.bernas.com.pl

    Can't upload files by rich:fileUpload

    kirkor.grzegorz.bernas.com.pl
      I'm trying to upload files. But without any errors I cant't. I use Seam 2.0.2 SP1 and I add newest RF lib 3.2.2.SR1
      Do I need to ad something to my components.xml or web.xml?
      My bean:
      `@AutoCreate
      @Name("fileUpload")
      @Scope(ScopeType.SESSION)
      public class FileUpload {
           
           @Logger
           Log log;

           private ArrayList<PersonFile> files = new ArrayList<PersonFile>();

           public int getSize() {
                log.info("size: " + getFiles().size());
                
                if (getFiles().size() > 0) {
                     return getFiles().size();
                } else {
                     return 0;
                }
           }
           
           public void listener(UploadEvent event) throws IOException {
                UploadItem item = event.getUploadItem();
                
                PersonFile pfile = new PersonFile();
                pfile.setFilename(item.getFileName());
                files.add(pfile);
                
               System.out.println("File : '" + item.getFileName() + "' was uploaded");
               if (item.isTempFile()) {
                File file = item.getFile();
                System.out.println("Absolute Path : '" + file.getAbsolutePath() + "'!");
                file.delete();
               }else {
                    try {
                          ByteArrayOutputStream b = new ByteArrayOutputStream();
                          b.write(item.getData());
                          System.out.println(b.toString());
                     } catch (Exception e) {
                          // TODO: handle exception
                     }
                
               }
           }

           public ArrayList<PersonFile> getFiles() {
                return files;
           }

           public void setFiles(ArrayList<PersonFile> files) {
                this.files = files;
           }

      }`
      My view:
      `<h:form>
                          <h:panelGrid columns="2" columnClasses="top,top">
                               <rich:fileUpload fileUploadListener="#{fileUpload.listener}" maxFilesQuantity="5" reRender="table" id="upload"
                                    immediateUpload="false" acceptedTypes="*" allowFlash="false" uploadData="#{fileUpload.files}">
                                    <a4j:support event="onuploadcomplete" reRender="info" />
                               </rich:fileUpload>
                               <h:panelGroup id="info">
                                    <rich:panel bodyClass="info">
                                         <f:facet name="header">
                                              <h:outputText value="Uploaded Files Info" />
                                         </f:facet>
                                         <h:outputText value="No files currently uploaded" rendered="#{fileUpload.size==0}" />
                                         <rich:dataGrid columns="1" value="#{fileUpload.files}" var="file" rowKeyVar="row">
                                              <rich:panel bodyClass="rich-laguna-panel-no-header">
                                                   <h:panelGrid columns="2">
                                                        <h:panelGrid columns="2">
                                                             <h:outputText value="File Name:" />
                                                             <h:outputText value="#{file.filename}" />
                                                        </h:panelGrid>
                                                   </h:panelGrid>
                                              </rich:panel>
                                         </rich:dataGrid>
                                    </rich:panel>
                                    <rich:spacer height="3" />
                                    <br />
                                    </h:panelGroup>
                          </h:panelGrid>
                     </h:form>`
        • 1. Re: Can't upload files by rich:fileUpload

          This is on my todo list, so I have not tried it yet.


          However, here are some posts I tagged that might be helpful


          http://www.seamframework.org/Documentation/HowToUploadAndDownloadFilesInSeam
          http://www.seamframework.org/Community/RichFileUploadSeam


          Regards

          • 2. Re: Can't upload files by rich:fileUpload
            kirkor.grzegorz.bernas.com.pl
            I try all of this... and none of them works.
            I even try update my project from Seam 2.0.2 to 2.1.0.
            This is what I have:
            OS: Ubuntu 8.10 64 bit
            Server: jboss-4.2.3.GA
            Seam: jboss-seam-2.1.0.SP1
            IDE: Eclipse 3.4 \+ JBoss Tools 3.0 beta 1
            I try to use rich:fileUpload and s:fileUpload none of this works.
            I have 3 pojects: WAR, EAR and EJB. I have class that I try to put into ejb and war without result. I try byte\[\], InputStrem and UploadEvent as a method to handle file.
            My xhtml file:

            |
            ...
            <h:form enctype="multipart/form-data">
                                   
                                            <s:fileUpload id="file" data="#{fileUpload.uploadedFileas}" accept="*" />
                                                                           
                                            <h:commandButton action="#{fileUpload.save}" value="upload">
                                            <f:param name="tab" value="personFiles" />
                                            </h:commandButton>
                                    </h:form>
            ...
            |

            my FileUpload.java in WAR project

            |
            ...
            @Name("fileUpload")
            @Scope(ScopeType.PAGE)
            public class FileUpload
            ...
                    public void listener(UploadEvent event) throws IOException {
                            log.info("Execute listener");
                    }
                   
                    public void data(byte[] data) {
                            log.info("get file...");
                    }
                    public void setUploadedFile(InputStream uploadedFile) {
                            log.info("upload...");
                            this.uploadedFile = uploadedFile;
                    }
            ...
            |
            in my components.xml I add:
            |
            ...
            <web:multipart-filter create-temp-files="true" max-request-size="100000000" url-pattern="*.seam"/>
                    <component class="org.jboss.seam.web.MultipartFilter">
                            <property name="createTempFiles">true</property>
                            <property name="maxRequestSize">1000000</property>
                    </component>
            ...
            |
            in my 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>
            |

            And what I get? NONE! Whe I try to upload file I don\'t get any error! Even more, if I try to use in data=\"\" none existing method from none existing class I still don\'t have any exceptions... Why? I truly don\'t know what to do... PLEASE HELP MY :(