use of com.liferay.faces.bridge.model.UploadedFile in project liferay-faces-bridge-impl by liferay.
the class InputFileRenderer method decode.
@Override
public void decode(FacesContext facesContext, UIComponent uiComponent) {
InputFile inputFile = (InputFile) uiComponent;
Map<String, List<UploadedFile>> uploadedFileMap = getUploadedFileMap(facesContext);
if (!uploadedFileMap.isEmpty()) {
String clientId = uiComponent.getClientId(facesContext);
List<UploadedFile> uploadedFiles = uploadedFileMap.get(clientId);
if ((uploadedFiles != null) && (uploadedFiles.size() > 0)) {
List<com.liferay.faces.bridge.model.UploadedFile> bridgeUploadedFiles = new ArrayList<com.liferay.faces.bridge.model.UploadedFile>(uploadedFiles.size());
for (UploadedFile uploadedFile : uploadedFiles) {
bridgeUploadedFiles.add(uploadedFile);
}
inputFile.setSubmittedValue(bridgeUploadedFiles);
// ActionListener.
for (UploadedFile uploadedFile : uploadedFiles) {
FileUploadEvent fileUploadEvent = new FileUploadEvent(uiComponent, uploadedFile);
uiComponent.queueEvent(fileUploadEvent);
}
} else // FACES-3136: Ensure that the required attribute is enforced.
{
inputFile.setSubmittedValue(Collections.emptyList());
}
} else // FACES-3136: Ensure that the required attribute is enforced.
{
inputFile.setSubmittedValue(Collections.emptyList());
}
}
use of com.liferay.faces.bridge.model.UploadedFile in project liferay-faces-bridge-impl by liferay.
the class FileUploadRendererPortletImpl method decode.
@Override
public void decode(FacesContext facesContext, UIComponent uiComponent) {
ExternalContext externalContext = facesContext.getExternalContext();
ClientDataRequest clientDataRequest = (ClientDataRequest) externalContext.getRequest();
ContextMapFactory contextMapFactory = (ContextMapFactory) FactoryExtensionFinder.getFactory(externalContext, ContextMapFactory.class);
Map<String, List<UploadedFile>> uploadedFileMap = (Map<String, List<UploadedFile>>) contextMapFactory.getUploadedFileMap(clientDataRequest);
if (!uploadedFileMap.isEmpty()) {
try {
externalContext.setRequest(new HttpServletRequestFileUploadAdapter(clientDataRequest, uploadedFileMap, externalContext));
super.decode(facesContext, uiComponent);
} finally {
externalContext.setRequest(clientDataRequest);
}
}
}
use of com.liferay.faces.bridge.model.UploadedFile in project liferay-faces-bridge-impl by liferay.
the class HttpServletRequestFileUploadAdapter method getParts.
@Override
public Collection<Part> getParts() throws IOException {
if (parts == null) {
List<Part> parts = new ArrayList<Part>();
Set<Map.Entry<String, List<UploadedFile>>> uploadedFileMapEntries = uploadedFileMap.entrySet();
for (Map.Entry<String, List<UploadedFile>> uploadedFileMapEntry : uploadedFileMapEntries) {
List<UploadedFile> uploadedFilesForName = uploadedFileMapEntry.getValue();
if ((uploadedFilesForName != null) && !uploadedFilesForName.isEmpty()) {
String partName = uploadedFileMapEntry.getKey();
for (UploadedFile uploadedFile : uploadedFilesForName) {
parts.add(new PartFileUploadAdapterImpl(uploadedFile, partName));
}
}
}
this.parts = Collections.unmodifiableList(parts);
}
return parts;
}
use of com.liferay.faces.bridge.model.UploadedFile in project liferay-faces-bridge-impl by liferay.
the class ApplicantBacking method uploadAttachments.
@SuppressWarnings("unchecked")
public void uploadAttachments(ActionEvent actionEvent) {
FacesContext facesContext = FacesContext.getCurrentInstance();
File attachmentDir = attachmentManager.getAttachmentDir(facesContext);
if (!attachmentDir.exists()) {
attachmentDir.mkdir();
}
try {
List<UploadedFile> attachments1 = (List<UploadedFile>) attachment1.getValue();
if (attachments1 != null) {
for (UploadedFile uploadedFile : attachments1) {
File copiedFile = new File(attachmentDir, uploadedFile.getName());
uploadedFile.write(copiedFile.getAbsolutePath());
uploadedFile.delete();
logger.debug("Received fileName=[{0}] absolutePath=[{1}]", copiedFile.getName(), copiedFile.getAbsolutePath());
}
}
List<UploadedFile> attachments2 = (List<UploadedFile>) attachment2.getValue();
if (attachments2 != null) {
for (UploadedFile uploadedFile : attachments2) {
File copiedFile = new File(attachmentDir, uploadedFile.getName());
uploadedFile.write(copiedFile.getAbsolutePath());
uploadedFile.delete();
logger.debug("Received fileName=[{0}] absolutePath=[{1}]", copiedFile.getName(), copiedFile.getAbsolutePath());
}
}
List<UploadedFile> attachments3 = (List<UploadedFile>) attachment3.getValue();
if (attachments3 != null) {
for (UploadedFile uploadedFile : attachments3) {
File copiedFile = new File(attachmentDir, uploadedFile.getName());
uploadedFile.write(copiedFile.getAbsolutePath());
uploadedFile.delete();
logger.debug("Received fileName=[{0}] absolutePath=[{1}]", copiedFile.getName(), copiedFile.getAbsolutePath());
}
}
List<Attachment> attachments = attachmentManager.getAttachments(attachmentDir);
applicant.setAttachments(attachments);
} catch (IOException e) {
logger.error(e);
}
applicantView.setFileUploaderRendered(false);
}
use of com.liferay.faces.bridge.model.UploadedFile in project liferay-faces-bridge-impl by liferay.
the class HttpServletRequestFileUploadAdapter method getPart.
@Override
public Part getPart(String name) throws IOException {
Part part = null;
List<UploadedFile> uploadedFiles = uploadedFileMap.get(name);
if ((uploadedFiles != null) && !uploadedFiles.isEmpty()) {
part = new PartFileUploadAdapterImpl(uploadedFiles.get(0), name);
}
return part;
}
Aggregations