How to know when fileUpload finishes all multiple uploads

UI Components for JSF
Post Reply
brabuh
Posts: 15
Joined: 26 May 2016, 04:42

13 Apr 2017, 14:07

So It has been awhile that I'm facing a problem with the fileUpload, because I need to know when the multiple uploads finishes so I can go on with my logic, I searched this in all over the stackoverflow and here, and I found some solutions that sometimes work just fine and sometimes they don't work at all.

my .xhtml code

Code: Select all


</style>
    <script>
    function doSomething(fileupload) {
        if (fileupload.files.length == 0) {
            save();
        }
    }    
</script>


<p:dialog widgetVar="dlgFiles" modal="true" resizable="false" width="800" height="400">
			<p:ajax event="close" update="@this, formProjetos" />
			<h:form id="newProjectForm" enctype="multipart/form-data">

				<div class="card card-w-title">
					<h1>Project Setup</h1>
					<p:panelGrid columns="1" layout="grid" styleClass="ui-panelgrid-blank form-group">
						<h:panelGroup styleClass="md-inputfield">
							<p:inputText id="projectNameInput" disabled="#{uploadBean.disableProjectName}" value="#{uploadBean.projectName}" required="true" requiredMessage="Project must have a name!">
								<o:validator validatorId="javax.faces.Length" minimum="2" maximum="15" message="Please enter a name between 2 and 15 characters" />
							</p:inputText>
							<p:message for="projectNameInput" />
							<label>Project Name</label>
						</h:panelGroup>
					</p:panelGrid>
					<div align="right">
						<p:commandButton value="Save" update="newProjectForm" actionListener="#{uploadBean.saveProjectName}" rendered="#{!uploadBean.disableProjectName}" icon="ui-icon-check" />
						<p:commandButton value="Edit" update="newProjectForm" actionListener="#{uploadBean.editProjectName}" rendered="#{uploadBean.disableProjectName}" icon="ui-icon-check" />
					</div>
				</div>

				<p:fileUpload id="fileUploaderBlast" fileLimit="5" fileLimitMessage="File limit is 5 per project" disabled="#{!uploadBean.disableProjectName}"
					fileUploadListener="#{uploadBean.handleFileUpload}" mode="advanced" dragDropSupport="false" widgetVar="myFileUploader" multiple="true"
					update="messagesFileUpload, newProjectForm" sizeLimit="100000000" allowTypes="/(\.|\/)(fastq|fq|sam|bam)$/" oncomplete="doSomething(PF('myFileUploader'));" />


			</h:form>
			
		</p:dialog>
		
		<h:form prependId="false">
             <p:remoteCommand name="save" actionListener="#{uploadBean.depoisFileupload}" process="@this" partialSubmit="true" />
            </h:form>


My bean code

Code: Select all

public void handleFileUpload(FileUploadEvent event) {
		FileSaver fileSaver = new FileSaver();
		UploadedFile file = event.getFile();
		NumberFormat formatter = new DecimalFormat("000");
		fileId++;
		FileUploaded fileUploaded = fileSaver.writeFile(file, getSessao().getId(),
				formatter.format(fileId), getProjectCount());
		project.addFileUploaded(fileUploaded);
		
		logger.info("Adicionando arquivo na lista: " + fileUploaded.getFileName());

		
	}

public void depoisFileupload() {
		
			project.getListaArquivosProjeto().sort((d1, d2) -> d1.getFileId().compareTo(d2.getFileId()));

			System.out.println(project);
			projetoDao.saveProject(project);

				addInfoMessageKeys("messagesFileUpload","The files were uploaded with sucess.");
			

			setDisableProjectName(false);
			
			setProjectName(new String());
			setProject(new Projetos());
			setListaProjetos(new ArrayList<>());
			setListaProjetos(projetoDao.listaProjetos(getSessao().getId()));

			RequestContext.getCurrentInstance().execute("PF('dlgFiles').hide()");
		

	}
	
	
So when the fileupload complete a upload then triggers the javascript and It's tested if the files.length is equals to 0, this method works fine when I have multiple files with pretty much the same size, but when I try to upload a 200kb file and a 33MB file, only the 200kb go through, I don't know why this is happen, can somebody help me?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 33 guests