當前位置: 首頁>>代碼示例>>Java>>正文


Java FileUploadEvent.getFile方法代碼示例

本文整理匯總了Java中org.primefaces.event.FileUploadEvent.getFile方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUploadEvent.getFile方法的具體用法?Java FileUploadEvent.getFile怎麽用?Java FileUploadEvent.getFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.primefaces.event.FileUploadEvent的用法示例。


在下文中一共展示了FileUploadEvent.getFile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleFileUpload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
public void handleFileUpload(FileUploadEvent event) {
	UploadedFile uploadedFile = event.getFile();
	String uploadedFileName = uploadedFile.getFileName();
	StringBuilder tmpFileNameBuilder = new StringBuilder();

	tmpFileNameBuilder.append(System.currentTimeMillis());
	tmpFileNameBuilder.append(".");
	tmpFileNameBuilder.append(FilenameUtils.getExtension(uploadedFileName));
	tmpFileName = tmpFileNameBuilder.toString();
	String tmpFilePath = getTmpFilePath();

	try {
		uploadedFile.write(tmpFilePath);
		cropImage = true;
		editing = false;
		editingSku = false;
	} catch (Exception e) {
		// logger.error("Erro ao salvar a imagem", e);
		addMessage("admin.produtos.erro_upload", FacesMessage.SEVERITY_ERROR);
	}
}
 
開發者ID:raphaelazzolini,項目名稱:mercurius,代碼行數:22,代碼來源:ProductsAdminMBean.java

示例2: handleFileUpload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
/**
 * Method used to handle an uploaded file.
 * Given file will be added to the list of uploaded files.
 */
public void handleFileUpload(FileUploadEvent event) {
    log.debug("Upload action called");
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ResourceBundle bundle = ResourceBundle.getBundle("messages",
            facesContext.getViewRoot().getLocale());
    if (event.getFile() != null && tempFileFolder != null) {
        log.debug("Upload success");
        files.add(event.getFile());
        logService.persist(Log.from(loggedInUser, course.getCourseId(),
                String.format("Uploaded the file %s.", event.getFile().getFileName())));
    } else {
        facesContext.addMessage(null, new FacesMessage(FacesMessage
                .SEVERITY_FATAL, bundle.getString("common.error"),
                bundle.getString("courses.create.uploadFail")));
    }
}
 
開發者ID:stefanoberdoerfer,項目名稱:exmatrikulator,代碼行數:21,代碼來源:StudentImportController.java

示例3: handleFileUpload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
public void handleFileUpload(FileUploadEvent event) {
    if (event != null) {
        file = event.getFile();
        if (elemento.getIdEvento() != null) {
            marketingUserFacade.guardarImagen(file.getContents(),
                    elemento.getIdEvento(),
                    file.getFileName().substring(file.getFileName().lastIndexOf("."),
                    file.getFileName().length()));
            elemento.setImagen(elemento.getIdEvento() + file.getFileName().substring(file.getFileName().lastIndexOf("."),
                    file.getFileName().length()));
        }
        FacesUtil.addInfoMessage(event.getFile().getFileName());
    }
}
 
開發者ID:ivanbanos,項目名稱:inversionesgit,代碼行數:15,代碼來源:MarketingEventoManejadorBean.java

示例4: handleFileUpload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
public void handleFileUpload(FileUploadEvent event) {

		String type = (String) event.getComponent().getAttributes().get("type");

		if (type.equals(LOGO_BANNER)) {
			logoBanner = event.getFile();
		}
		if (type.equals(LOGO_HEADER)) {
			logoHeader = event.getFile();
		}
		if (type.equals(LOGO_FOOTER)) {
			logoFooter = event.getFile();
		}

		facesContext
				.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
						"Información", "Logo " + event.getFile().getFileName()
								+ " subido con éxito."));
	}
 
開發者ID:alefq,項目名稱:asistente-eventos,代碼行數:20,代碼來源:EventoEditMB.java

示例5: handleUpload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
/**
 * Upload input data for import
 * @param event upload event
 */
public void handleUpload(FileUploadEvent event) {
    try {
        this.uploadedFile = event.getFile();
        this.messageUtil.infoText("File name: " +
                event.getFile().getFileName() + " file size: " +
                event.getFile().getSize() / 1024 + " Kb content type: " +
                event.getFile().getContentType() + " The document file was uploaded.");
    }
    catch (Exception err) {
        this.messageUtil.error(err);
    }
}
 
開發者ID:ddRPB,項目名稱:rpb,代碼行數:17,代碼來源:OCImportBean.java

示例6: handleUpload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
/**
 * Upload input data for import
 * @param event upload event
 */
public void handleUpload(FileUploadEvent event) {
    try {
        this.uploadedFile = event.getFile();

        this.messageUtil.infoText("File name: " +
                event.getFile().getFileName() + " file size: " +
                event.getFile().getSize() / 1024 + " Kb content type: " +
                event.getFile().getContentType() + " The document file was uploaded.");
    }
    catch (Exception err) {
        this.messageUtil.error(err);
    }
}
 
開發者ID:ddRPB,項目名稱:rpb,代碼行數:18,代碼來源:DataMappingBean.java

示例7: upload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
public void upload(FileUploadEvent event) throws IOException {

		try {
			file = event.getFile();

			FacesContext aFacesContext = FacesContext.getCurrentInstance();
			ServletContext context = (ServletContext) aFacesContext.getExternalContext().getContext();

			String realPath = context.getRealPath("/resources/ApostilasEnviadas/");

			byte[] arquivo = file.getContents();
			String caminho = realPath + file.getFileName();
			System.out.println("caminho apostila: " + caminho);

			// esse trecho grava o arquivo no diretório
			FileOutputStream fos = new FileOutputStream(caminho);
			fos.write(arquivo);
			fos.close();

			FacesContext instance = FacesContext.getCurrentInstance();
			instance.addMessage("mensagens",
					new FacesMessage(FacesMessage.SEVERITY_INFO, file.getFileName() + "Sucesso", null));

		} catch (Exception ex) {
			System.out.println("Erro no upload de imagem" + ex);
		}
	}
 
開發者ID:Corlobin,項目名稱:Pecomp,代碼行數:28,代碼來源:AdicionaApostilaBean.java

示例8: handleFileUpload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
public void handleFileUpload(FileUploadEvent event) {
    FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
    FacesMessage messageError = new FacesMessage("Error", "Não foi possível carregar o arquivo. Contate o administrador");

    UploadedFile uploadedFile = event.getFile();

    try {

        FileUtils.copyFile(uploadedFile, Propriedades.MAP_PASTAS.get("PASTA_WEB"));
        uploadedFile.getInputstream().close();
        FacesContext.getCurrentInstance().addMessage(null, message);

        System.out.println(Thread.currentThread().getId() + ": Arquivo <" + event.getFile().getFileName() + "> carregado com sucesso");

    } catch (IOException ex) {
        Logger.getLogger(FileUploadView.class.getName()).log(Level.SEVERE, null, ex);
        FacesContext.getCurrentInstance().addMessage(null, messageError);
    }
}
 
開發者ID:blastin,項目名稱:Service,代碼行數:20,代碼來源:FileUploadView.java

示例9: handleFileUpload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
/**
 * Handles file upload events.
 */
public void handleFileUpload(FileUploadEvent event) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ResourceBundle bundle = ResourceBundle.getBundle("messages",
            facesContext.getViewRoot().getLocale());

    UploadedFile file = event.getFile();
    if (file == null) {
        facesContext.addMessage(null, new FacesMessage(FacesMessage
            .SEVERITY_FATAL, bundle.getString("common.error"),
            bundle.getString("courses.create.uploadFail")));
        return;
    }

    files.add(file);
    logFileUploaded(file);
}
 
開發者ID:stefanoberdoerfer,項目名稱:exmatrikulator,代碼行數:20,代碼來源:TmeController.java

示例10: upload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
public void upload(FileUploadEvent event) {
    final UploadedFile file = event.getFile();
    if (file == null) return;

    FacesMessage message;
    try {
        linksInspector.from(file.getInputstream());

        message = new FacesMessage("Leídas con éxito " + linksInspector.getLinks().size() + " URLs del fichero: " + file.getFileName(), "");

    } catch (IOException e) {
        message = new FacesMessage(SEVERITY_ERROR, "No se puede leer el fichero: " + file.getFileName(), e.getLocalizedMessage());
        e.printStackTrace();
    }

    FacesContext.getCurrentInstance().addMessage(null, message);
}
 
開發者ID:autentia,項目名稱:urmiche,代碼行數:18,代碼來源:InspectUrlsView.java

示例11: handleFileUpload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
@TsLoggedIn
public void handleFileUpload(FileUploadEvent event) throws Exception {
    UploadedFile item = event.getFile();
    if (item != null) {
        try {
            UploadedFileIterator uploadedFileIterator = new UploadedFileIterator(item, "csv", "txt", "xml");
            StringBuilder sb = new StringBuilder();
            int count = 0;
            FileInputStreamWrapper w = uploadedFileIterator.getNext();
            while (w != null) {
                createDataFile(w.getFileName(), w.getInputStream());
                if (sb.length() != 0) {
                    sb.append(", ");
                }
                sb.append(w.getFileName());
                w = uploadedFileIterator.getNext();
                count++;
            }

            if (sb.length() == 0) {
                messages.warn("The uploaded archive, '" + item.getFileName()
                        + "' file did not have any valid files.");
            } else {
                messages.info("Added " + count + " files.");
            }
        } catch (Exception e) {
            LOG.error("Error extracting zip file: " + e.toString());
            messages.error("Error extracting zip file: " + e.toString());
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(item.getInputstream());
        }
    }
}
 
開發者ID:intuit,項目名稱:Tank,代碼行數:35,代碼來源:FileUploadBean.java

示例12: handleFileUpload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
@TsLoggedIn
public void handleFileUpload(FileUploadEvent event) throws Exception {
    UploadedFile item = event.getFile();

    if (item != null) {
        try {
            UploadedFileIterator uploadedFileIterator = new UploadedFileIterator(item, "xml");
            StringBuilder sb = new StringBuilder();
            FileInputStreamWrapper w = uploadedFileIterator.getNext();
            while (w != null) {
                processScript(w.getInputStream(), w.getFileName());
                if (sb.length() != 0) {
                    sb.append(", ");
                }
                sb.append(w.getFileName());
                w = uploadedFileIterator.getNext();

            }
        } catch (Exception e) {
            LOG.error("Error extracting zip file: " + e.toString());
            messages.error("Error extracting zip file: " + e.toString());
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(item.getInputstream());
        }
    }
}
 
開發者ID:intuit,項目名稱:Tank,代碼行數:28,代碼來源:TankXmlUploadBean.java

示例13: handleFileUpload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
public void handleFileUpload(FileUploadEvent event) {
	UploadedFile file = event.getFile();
	log.info("File uploaded: " + file.getFileName());
	FileEntity fe = new FileEntity();
	fe.setId(fakeFileId--);
	fe.setFileName(file.getFileName());
	fe.setContent(file.getContents());
	fe.setContentType(file.getContentType());

	fileList.add(fe);

}
 
開發者ID:awizen,項目名稱:gangehi,代碼行數:13,代碼來源:FileListView.java

示例14: handleFileUpload

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
public void handleFileUpload(FileUploadEvent event) {
	UploadedFile uploadedFile = event.getFile();
	bucketObject.setContentType(uploadedFile.getContentType());
	bucketObject.setSize(uploadedFile.getSize());
	
	if (contentDispositionFilename == null || contentDispositionFilename.isEmpty()) {
		this.contentDispositionFilename = uploadedFile.getFileName();
	}
	
	try (InputStream is = event.getFile().getInputstream()) {
		Path tempFile = Files.createTempFile(null, null);
		Files.copy(is, tempFile, StandardCopyOption.REPLACE_EXISTING);
		this.content = new LazyFileInputStream(tempFile);
	} catch (IOException ex) {
		LOG.log(Level.SEVERE, "Could not locally save the file!", ex);
	}
}
 
開發者ID:Blazebit,項目名稱:blaze-storage,代碼行數:18,代碼來源:BucketObjectAddPage.java

示例15: uploadFile

import org.primefaces.event.FileUploadEvent; //導入方法依賴的package包/類
public void uploadFile( FileUploadEvent event ) {
	try {
		UploadedFile file = event.getFile();
		InputStream is = file.getInputstream();
		OutputStream os = new FileOutputStream(new File(getTmpDir(), file.getFileName()));
		IOUtils.copy(is, os);
		is.close();
		os.close();
		files.add(file.getFileName());
		if( isUsingMsf() )
			getCfg().setPsmScore(ScoreType.SEQUEST_XCORR);
	} catch( Exception e ) {			
	}
}
 
開發者ID:akrogp,項目名稱:EhuBio,代碼行數:15,代碼來源:ExperimentMB.java


注:本文中的org.primefaces.event.FileUploadEvent.getFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。