File upload async problems

UI Components for JSF
Post Reply
jmcollin92
Posts: 145
Joined: 05 Nov 2009, 22:32

25 Mar 2010, 13:39

Hello,

I've got a basic form with a fileUpload in it. I want that the upload start when the user click on the submit button of the form.
So I've implemented that like this :

Code: Select all

<h:form id="fileTransfertView1UploadForm" prependId="false">	
 		<h:panelGrid columns="2">        
		    <h:outputLabel value="#{messages['file1']} :" for="fileTransfertView1UploadFormfile1"/>
                    <p:fileUpload widgetVar="widgetVar" id="fileTransfertView1UploadFormfile1" label="#{messages['file1']}:" fileUploadListener="#{fileTransfertTestControler.uploadFile1}" customUI="true"/>
 		</h:panelGrid>

        <p:commandButton id="fileTransfertView1UploadAction" value="#{messages['upload']}" action="#{fileTransfertTestControler.fileTransfertView1Upload}"
			onclick="widgetVar.upload();" ajax="true" update="messagesDialog, fileTransfertView1UploadForm"/>
</h:form>
This works well for small file but not with larger file because the action (#{fileTransfertTestControler.fileTransfertView1Upload} in this case) is fired before file upload is complete.

Is there a way to make the upload synchrone (ie : widgetVar.upload() returns when upload is complete) ?

Thank's for any help.
----
Primefaces 2.0.1-SNAPSHOT
JBoss 6.0.0-M2
Mojorra 2.0.2
---

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

26 Mar 2010, 13:41

This looks tricky.

Why can't you move the logic of button action to the fileUploadListener and update="messagesDialog, fileTransfertView1UploadForm" to p:fileUpload.

Then you can upload the files with a button click using;

Code: Select all

<p:commandButton id="fileTransfertView1UploadAction" value="#{messages['upload']}" onclick="widgetVar.upload();return false;"/>

jmcollin92
Posts: 145
Joined: 05 Nov 2009, 22:32

26 Mar 2010, 17:24

yes, in this very little it will work (and I appreciate the idea ...), but in a more real world, the button should also commit form input component.
In the best case, I would like the button to :
1. transfert file(s),
2. wait for files to be transfered (maybe it's possible in JS with ajaxStatus or something equivalent ?),
3. submit the form like usual.

If it is not possible out of the box, I will do totally differently.

Thank's anymay.
----
Primefaces 2.0.1-SNAPSHOT
JBoss 6.0.0-M2
Mojorra 2.0.2
---

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Bogdanbgr and 38 guests