Page 1 of 1

Two fileUploads inside one form

Posted: 08 Jun 2012, 06:23
by nurzhan.izbassov
Hi!

I am using Primefaces 3.3. I need to use two fileUploads in advanced mode inside one form. The problem that I encounter is that when I upload some file using the first fileUpload it seems that the second fileUpload gets also activated since it shows the same file name to upload, although I don't click on the second fileUpload.

How can I solve this problem?

Thanks in advance.

Re: Two fileUploads inside one form

Posted: 08 Jun 2012, 09:12
by andyba
nurzhan.izbassov wrote:Hi!

I am using Primefaces 3.3. I need to use two fileUploads in advanced mode inside one form. The problem that I encounter is that when I upload some file using the first fileUpload it seems that the second fileUpload gets also activated since it shows the same file name to upload, although I don't click on the second fileUpload.

How can I solve this problem?

Thanks in advance.
You need to publish your code.
You need to read the User Guide.

Re: Two fileUploads inside one form

Posted: 13 Jun 2012, 08:16
by noboundaries
Facing similar issue. Going to look around the user guide bu the mean time please share if any suggestions!

Tomcat 6.0.32, JAVA5, Primefaces 3.2, windows 7,

Below is My view

Code: Select all

 <h:form  enctype="multipart/form-data">
            <p:growl id="messages" showDetail="true" showSummary="true" sticky="true"/>

          
                <p:fileUpload id="upload1" fileUploadListener="#{fileUploadBean.handleFileUpload1}"  
                              mode="advanced"  label="file1"
                              auto="true" immediate="true"  
                              sizeLimit="1000000"  
                              update="messages"
                              allowTypes="/(\.|\/)(xml)$/"  />  

                     
                <p:fileUpload id="upload2" fileUploadListener="#{fileUploadBean.handleFileUpload2}"  
                              mode="advanced"   label="file2"
                              auto="true"
                              sizeLimit="1000000"    
                              update="messages"
                              allowTypes="/(\.|\/)(xml)$/" />  

          
        </h:form>

And Below is my bean methods

Code: Select all

public void handleFileUpload1(FileUploadEvent event) {
         System.out.println("****Starting File Upload ****");
              
        FacesContext context = FacesContext.getCurrentInstance();  
          
        context.addMessage(null, new FacesMessage("First File ", event.getFile().getFileName() + " is uploaded."));  
        context.addMessage(null, new FacesMessage("Second Message", "Additiona1 Info Here..."));  
        
         System.out.println("**** File Upload End ****");
    }
    
    
    public void handleFileUpload2(FileUploadEvent event) {
         System.out.println("****Starting File Upload ****");
              
        FacesContext context = FacesContext.getCurrentInstance();  
          
        context.addMessage(null, new FacesMessage("Second File", event.getFile().getFileName() + " is uploaded."));  
        context.addMessage(null, new FacesMessage("Second Message", "Additional Info Here..."));  
        
         System.out.println("**** File Upload End ****");
    }
}

Re: Two fileUploads inside one form

Posted: 11 Jul 2012, 10:07
by ravisankar.vvvsrk
Multiple advanced uploaders in same form is not supported at the moment.
refer the primefaces 3.3 pdf pageno :182

Re: Two fileUploads inside one form

Posted: 11 Jul 2012, 11:53
by T.dot

Re: Two fileUploads inside one form

Posted: 11 Jul 2012, 14:32
by andyba
I have seen a lot of posts about having multiple file uploads in the same form and I ask myself why?
Having more than one on a page can be justified sure but in the same form?
You can easily split them up across multiple forms even inside the same page.

I would also recommend using different beans dependent on where and why files are being uploaded.
You can reduce DRY conflicts by using a suitable superclass to handle the donkey work and extend them for each bean.
The reason I suggest this is because so many people try packing everything into one bean (where at least 2 are recommended, one request bean as receiver and either a session, view or conversation bean to track things after the uploads are finished) and end up with a mass of event methods, file properties and hardcoded dross.