Two fileUploads inside one form

UI Components for JSF
Post Reply
nurzhan.izbassov
Posts: 6
Joined: 29 Mar 2012, 13:18

08 Jun 2012, 06:23

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.

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

08 Jun 2012, 09:12

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.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

noboundaries
Posts: 4
Joined: 13 Jun 2012, 07:54

13 Jun 2012, 08:16

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 ****");
    }
}

ravisankar.vvvsrk
Posts: 5
Joined: 26 Jun 2012, 10:48

11 Jul 2012, 10:07

Multiple advanced uploaders in same form is not supported at the moment.
refer the primefaces 3.3 pdf pageno :182

User avatar
T.dot
Expert Member
Posts: 620
Joined: 01 Feb 2012, 15:39
Location: Vienna/Austria

11 Jul 2012, 11:53


User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

11 Jul 2012, 14:32

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.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

Post Reply

Return to “PrimeFaces”

  • Information