本文整理匯總了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);
}
}
示例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")));
}
}
示例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());
}
}
示例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."));
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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());
}
}
}
示例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());
}
}
}
示例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);
}
示例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);
}
}
示例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 ) {
}
}