本文整理匯總了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);
}
}