Search in sources :

Example 1 with UploadedFile

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());
    }
}
Also used : ArrayList(java.util.ArrayList) InputFile(com.liferay.faces.bridge.component.inputfile.InputFile) UploadedFile(com.liferay.faces.bridge.model.UploadedFile) FileUploadEvent(com.liferay.faces.bridge.event.FileUploadEvent) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with UploadedFile

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);
        }
    }
}
Also used : ClientDataRequest(javax.portlet.ClientDataRequest) ContextMapFactory(com.liferay.faces.bridge.context.map.internal.ContextMapFactory) UploadedFile(com.liferay.faces.bridge.model.UploadedFile) ExternalContext(javax.faces.context.ExternalContext) List(java.util.List) Map(java.util.Map)

Example 3 with UploadedFile

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;
}
Also used : UploadedFile(com.liferay.faces.bridge.model.UploadedFile) Part(javax.servlet.http.Part) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with UploadedFile

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);
}
Also used : FacesContext(javax.faces.context.FacesContext) UploadedFile(com.liferay.faces.bridge.model.UploadedFile) List(java.util.List) Attachment(com.liferay.faces.demos.applicant.jsf.jsp.dto.Attachment) IOException(java.io.IOException) File(java.io.File) UploadedFile(com.liferay.faces.bridge.model.UploadedFile) InputFile(com.liferay.faces.bridge.component.inputfile.InputFile)

Example 5 with UploadedFile

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;
}
Also used : UploadedFile(com.liferay.faces.bridge.model.UploadedFile) Part(javax.servlet.http.Part)

Aggregations

UploadedFile (com.liferay.faces.bridge.model.UploadedFile)10 List (java.util.List)6 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 FacesContext (javax.faces.context.FacesContext)3 Part (javax.servlet.http.Part)3 InputFile (com.liferay.faces.bridge.component.inputfile.InputFile)2 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ExternalContext (javax.faces.context.ExternalContext)2 ContextMapFactory (com.liferay.faces.bridge.context.map.internal.ContextMapFactory)1 FileUploadEvent (com.liferay.faces.bridge.event.FileUploadEvent)1 UploadedFileBridgeImpl (com.liferay.faces.bridge.model.internal.UploadedFileBridgeImpl)1 PartFileUploadAdapterImpl (com.liferay.faces.bridge.renderkit.bridge.internal.PartFileUploadAdapterImpl)1 Attachment (com.liferay.faces.demos.applicant.jsf.jsp.dto.Attachment)1 Attachment (com.liferay.faces.demos.applicant.richfaces.facelets.dto.Attachment)1 FacesRequestParameterMap (com.liferay.faces.util.context.map.FacesRequestParameterMap)1 MultiPartFormData (com.liferay.faces.util.context.map.MultiPartFormData)1 Product (com.liferay.faces.util.product.Product)1