本文整理汇总了Java中org.primefaces.event.FileUploadEvent类的典型用法代码示例。如果您正苦于以下问题:Java FileUploadEvent类的具体用法?Java FileUploadEvent怎么用?Java FileUploadEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileUploadEvent类属于org.primefaces.event包,在下文中一共展示了FileUploadEvent类的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包/类
/**
* This handles a file upload from the html page
*
* @param event event containing file data and type
*/
public void handleFileUpload(FileUploadEvent event) {
LOGGER.trace("Uploading image");
//load the person again just to be save
showLoggedInPerson();
//save the image
personService.savePersonImage(bean.getPerson(), event.getFile().getContents(), event.getFile().getContentType());
//set the url on the person to our image retrieval servlet so we can show the image we just uploaded
bean.getPerson().setImageUrl("/swd14-fe/personImage?id=" + bean.getPerson().getId());
//redirect to the page we came from, in order to reload the page
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
try {
ec.redirect(((HttpServletRequest) ec.getRequest()).getRequestURI());
LOGGER.trace("Image upload complete");
} catch (IOException ex) {
bean.growl("Internal Error", "Error during page refresh");
LOGGER.error("Error during page refresh", ex);
}
}
示例3: 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")));
}
}
示例4: uploadCertAdmin
import org.primefaces.event.FileUploadEvent; //导入依赖的package包/类
/**
* Event Handler do componente {@link FileUpload}, para adicionar um
* administrador ao cadastro.
* @param event Objeto Event do componente FileUpload (Primefaces).
*/
public void uploadCertAdmin(FileUploadEvent event) {
if (JBossUtil.TCC_FIAP_RESTRICT_USER_CHANGES) {
FacesUtil.addFacesMessage(
"Fun\u00E7\u00E3o n\u00E3o dispon\u00EDvel nesta instala\u00E7\u00E3o.",
null, FacesMessage.SEVERITY_WARN);
} else {
try {
icpAdmin.adicionarAdmin(event.getFile().getInputstream());
FacesUtil.addFacesMessage("Usu\u00E1rio adicionado com sucesso.",
null, FacesMessage.SEVERITY_INFO);
atualizarListaUsuarios();
} catch (Exception e) {
FacesUtil.addFacesMessage("Erro ao adicionar o usu\u00E1rio.",
e.getLocalizedMessage(), FacesMessage.SEVERITY_ERROR);
}
}
}
示例5: uploadCertAdmin
import org.primefaces.event.FileUploadEvent; //导入依赖的package包/类
/**
* Event Handler do componente {@link FileUpload}, para adicionar um
* administrador ao cadastro.
* @param event Objeto Event do componente FileUpload (Primefaces).
*/
public void uploadCertAdmin(FileUploadEvent event) {
if (JBossUtil.TCC_FIAP_RESTRICT_USER_CHANGES) {
FacesUtil.addFacesMessage(
"Fun\u00E7\u00E3o n\u00E3o dispon\u00EDvel nesta instala\u00E7\u00E3o.",
null, FacesMessage.SEVERITY_WARN);
} else {
try {
receitaEngine.adicionarAdmin(event.getFile().getInputstream());
FacesUtil.addFacesMessage("Usu\u00E1rio adicionado com sucesso.",
null, FacesMessage.SEVERITY_INFO);
usuarioLogado = super.getUsuarioLogin();
atualizarListaUsuarios();
} catch (Exception e) {
FacesUtil.addFacesMessage("Erro ao adicionar o usu\u00E1rio.",
e.getLocalizedMessage(), FacesMessage.SEVERITY_ERROR);
}
}
}
示例6: uploadCertCidadao
import org.primefaces.event.FileUploadEvent; //导入依赖的package包/类
/**
* Event Handler do componente {@link FileUpload}, para adicionar um
* certificado de cidadao ao cadastro.
* @param event Objeto Event do componente FileUpload (Primefaces).
*/
public void uploadCertCidadao(FileUploadEvent event) {
try {
InputStream istream = event.getFile().getInputstream();
X509Certificate cert =
CertificadoSerializador.loadCertFromStream(istream);
String content =
CertificadoSerializador.certToStr(cert);
newCidadao = sicidEngine.getCidadaoInfoFromCert(content);
if (newCidadao == null) {
criaNovoCidadao();
}
} catch (Exception e) {
FacesUtil.addFacesMessage("Erro ao obter informa\u00E7\u00F5es do certificado.",
e.getLocalizedMessage(), FacesMessage.SEVERITY_ERROR);
}
}
示例7: uploadCertAdministrador
import org.primefaces.event.FileUploadEvent; //导入依赖的package包/类
/**
* Event Handler do componente {@link FileUpload}, para adicionar um
* administrador ao cadastro.
* @param event Objeto Event do componente FileUpload (Primefaces).
*/
public void uploadCertAdministrador(FileUploadEvent event) {
if (JBossUtil.TCC_FIAP_RESTRICT_USER_CHANGES) {
FacesUtil.addFacesMessage(
"Fun\u00E7\u00E3o n\u00E3o dispon\u00EDvel nesta instala\u00E7\u00E3o.",
null, FacesMessage.SEVERITY_WARN);
} else {
try {
sicidEngine.adicionarAdministrador(event.getFile().getInputstream());
FacesUtil.addFacesMessage("Usu\u00E1rio adicionado com sucesso.",
null, FacesMessage.SEVERITY_INFO);
atualizarListaUsuarios();
} catch (Exception e) {
FacesUtil.addFacesMessage("Erro ao adicionar o usu\u00E1rio.",
e.getLocalizedMessage(), FacesMessage.SEVERITY_ERROR);
}
}
}
示例8: uploadCertGerente
import org.primefaces.event.FileUploadEvent; //导入依赖的package包/类
/**
* Event Handler do componente {@link FileUpload}, para adicionar um
* gerente ao cadastro.
* @param event Objeto Event do componente FileUpload (Primefaces).
*/
public void uploadCertGerente(FileUploadEvent event) {
if (JBossUtil.TCC_FIAP_RESTRICT_USER_CHANGES) {
FacesUtil.addFacesMessage(
"Fun\u00E7\u00E3o n\u00E3o dispon\u00EDvel nesta instala\u00E7\u00E3o.",
null, FacesMessage.SEVERITY_WARN);
} else {
try {
bancoEngine.adicionarGerente(event.getFile().getInputstream());
FacesUtil.addFacesMessage("Usu\u00E1rio adicionado com sucesso.",
null, FacesMessage.SEVERITY_INFO);
usuarioLogado = super.getUsuarioLogin();
atualizarListaUsuarios();
} catch (Exception e) {
FacesUtil.addFacesMessage("Erro ao adicionar o usu\u00E1rio.",
e.getLocalizedMessage(), FacesMessage.SEVERITY_ERROR);
}
}
}
示例9: testHandleFileUploadError
import org.primefaces.event.FileUploadEvent; //导入依赖的package包/类
@Test
public void testHandleFileUploadError() {
try {
when(nativeUploadedFile.getInputstream()).thenThrow(
new IOException());
FileUploadEvent event = new FileUploadEvent(uiComponent,
nativeUploadedFile);
fileUploadManager.handleFileUpload(event);
assertEquals(0, fileUploadManager.getUploadedFiles().size());
assertEquals("3", fileUploadManager.getCurrentFileLimit());
} catch (IOException ioException) {
fail("no exception should be thrown");
}
}
示例10: testGetImageFile
import org.primefaces.event.FileUploadEvent; //导入依赖的package包/类
@Test
public void testGetImageFile() {
FileUploadEvent event = new FileUploadEvent(uiComponent,
nativeUploadedFile);
fileUploadManager.handleFileUpload(event);
Map<String, String> requestParameterMap = new HashMap<String, String>();
requestParameterMap.put("uploadedFileId", fileUploadManager
.getUploadedFiles().get(0).getId());
when(facesContext.getCurrentPhaseId()).thenReturn(null);
when(facesContext.getExternalContext()).thenReturn(
externalContext);
when(externalContext.getRequestParameterMap()).thenReturn(
requestParameterMap);
assertEquals("image/png", fileUploadManager.getImage()
.getContentType());
}
示例11: testGetImageFileError
import org.primefaces.event.FileUploadEvent; //导入依赖的package包/类
@Test
public void testGetImageFileError() {
FileUploadEvent event = new FileUploadEvent(uiComponent,
nativeUploadedFile);
fileUploadManager.handleFileUpload(event);
Map<String, String> requestParameterMap = new HashMap<String, String>();
requestParameterMap.put("uploadedFileId", "123");
when(facesContext.getCurrentPhaseId()).thenReturn(null);
when(facesContext.getExternalContext()).thenReturn(
externalContext);
when(externalContext.getRequestParameterMap()).thenReturn(
requestParameterMap);
assertNotNull(fileUploadManager.getImage());
}
示例12: imageUploaded
import org.primefaces.event.FileUploadEvent; //导入依赖的package包/类
/**
* Imagem enviada
*
* @param event
*/
public void imageUploaded(FileUploadEvent event) {
File tempFile = createTempFile(event.getFile());
if (tempFile != null) {
if (this.file != null) {
this.file.delete();
this.file = tempFile;
this.contentType = event.getFile().getContentType();
} else {
this.file = tempFile;
this.contentType = event.getFile().getContentType();
}
} else {
LiferayFacesContext.getInstance().addGlobalErrorMessage("Ocorreu um erro ao importar a imagem.");
}
showUpdateImage = false;
}
示例13: handleSQLScriptUpload
import org.primefaces.event.FileUploadEvent; //导入依赖的package包/类
/**
*
*
* @param event
*/
public void handleSQLScriptUpload(FileUploadEvent event) {
String folder = "0";
if (scenario != null) {
folder = String.valueOf(scenario.getId());
}
scriptFile = uploader.handleUpload(event, folder);
scriptPath = scriptFile.getName();
Severity sev = FacesMessage.SEVERITY_INFO;
FacesMessage msg = new FacesMessage(sev, Cfg.inst().getProp(DEF_LANGUAGE, "EDIT_SC.UPLOAD_SUCCESS"),
scriptPath != null ? Cfg.inst().getProp(DEF_LANGUAGE, "EDIT_SC.NEW_NAME")
+ ": " + scriptPath : "");
FacesContext.getCurrentInstance().addMessage(null, msg);
scriptStream = uploader.getFileToDownload(scriptFile);
}
示例14: handleImageUpload
import org.primefaces.event.FileUploadEvent; //导入依赖的package包/类
/**
*
*
* @param event
*/
public void handleImageUpload(FileUploadEvent event) {
String folder = "0";
if (scenario != null) {
folder = String.valueOf(scenario.getId());
}
imageFile = uploader.handleUpload(event, folder);
imagePath = imageFile.getName();
Severity sev = FacesMessage.SEVERITY_INFO;
FacesMessage msg = new FacesMessage(sev, Cfg.inst().getProp(DEF_LANGUAGE, "EDIT_SC.UPLOAD_SUCCESS"),
imagePath != null ? Cfg.inst().getProp(DEF_LANGUAGE, "EDIT_SC.NEW_NAME")
+ ": " + imagePath : "");
FacesContext.getCurrentInstance().addMessage(null, msg);
imageStream = uploader.getFileToDownload(imageFile);
}
示例15: receberImagemPais
import org.primefaces.event.FileUploadEvent; //导入依赖的package包/类
/**
* Recebe a imagem via fileupload.
*
* @param event
*/
public void receberImagemPais(FileUploadEvent event) {
try {
byte[] imagemRecebida = IOUtils.toByteArray(event.getFile().getInputstream());
paisBean.setImagem(imagemRecebida);
imagemController.setImagemTemp(imagemRecebida);
} catch (Throwable ex) {
System.out.print("Erro ao receber a imagem via file upload: " + ex.getMessage());
FacesMessage mensagem = new FacesMessage(FacesMessage.SEVERITY_FATAL, "Ocorreu um erro no upload da imagem: "
+ ex.getMessage(), null);
FacesContext.getCurrentInstance().addMessage(null, mensagem);
}
}