Search in sources :

Example 1 with InputFile

use of com.liferay.faces.alloy.component.inputfile.InputFile in project liferay-faces-alloy 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, inputFile.getLocation());
    if (uploadedFileMap != null) {
        String clientId = uiComponent.getClientId(facesContext);
        List<UploadedFile> uploadedFiles = uploadedFileMap.get(clientId);
        if ((uploadedFiles != null) && (uploadedFiles.size() > 0)) {
            inputFile.setSubmittedValue(uploadedFiles);
            // 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 : UploadedFile(com.liferay.faces.util.model.UploadedFile) FileUploadEvent(com.liferay.faces.alloy.component.inputfile.FileUploadEvent) List(java.util.List) InputFile(com.liferay.faces.alloy.component.inputfile.InputFile)

Example 2 with InputFile

use of com.liferay.faces.alloy.component.inputfile.InputFile in project liferay-faces-alloy by liferay.

the class InputFileDelegationResponseWriter method startElement.

@Override
public void startElement(String name, UIComponent uiComponent) throws IOException {
    super.startElement(name, uiComponent);
    if ("input".equals(name)) {
        InputFile inputFile = (InputFile) uiComponent;
        String multiple = inputFile.getMultiple();
        if ("multiple".equalsIgnoreCase(multiple)) {
            super.writeAttribute("multiple", multiple, "multiple");
        }
    }
}
Also used : InputFile(com.liferay.faces.alloy.component.inputfile.InputFile)

Example 3 with InputFile

use of com.liferay.faces.alloy.component.inputfile.InputFile in project liferay-faces-alloy by liferay.

the class InputFileRenderer method encodeMarkupEnd.

@Override
public void encodeMarkupEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    // If the component should show the progress table, then
    InputFile inputFile = (InputFile) uiComponent;
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    if (inputFile.isShowProgress()) {
        // Finish encoding of the outermost <div> element. Since the template contains its own "Select Files"
        // button, delegation must not occur.
        responseWriter.endElement("div");
    } else // Otherwise, if the component should show the preview table, then
    if (inputFile.isShowPreview()) {
        encodePreview(facesContext, responseWriter, inputFile);
        // Finish encoding of the outermost <div> element.
        responseWriter.endElement("div");
    } else // Otherwise, delegate writing of the entire <input type="file"...> ... </input> element to the delegate
    // renderer.
    {
        ResponseWriter delegationResponseWriter = new InputFileDelegationResponseWriter(responseWriter, inputFile.isAuto());
        super.encodeMarkupEnd(facesContext, uiComponent, delegationResponseWriter);
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) InputFile(com.liferay.faces.alloy.component.inputfile.InputFile)

Example 4 with InputFile

use of com.liferay.faces.alloy.component.inputfile.InputFile in project liferay-faces-alloy by liferay.

the class InputFileRenderer method encodeJavaScriptCustom.

@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    InputFile inputFile = (InputFile) uiComponent;
    // Determine the valid content-types and maximum file size from the validator (if specified).
    String validContentTypesString = inputFile.getContentTypes();
    JavaScriptFragment[] validContentTypes;
    if ((validContentTypesString == null) || "".equals(validContentTypesString)) {
        validContentTypes = new JavaScriptFragment[] {};
    } else {
        validContentTypes = AlloyRendererUtil.toEscapedJavaScriptStringArray(validContentTypesString.split("\\s*,\\s*"));
    }
    String clientId = inputFile.getClientId(facesContext);
    Long maxFileSize = inputFile.getMaxFileSize();
    if (maxFileSize == null) {
        maxFileSize = Long.MAX_VALUE;
    }
    // If the component should render the upload progress table, then initialize the YUI progress uploader widget.
    if (inputFile.isShowProgress()) {
        String clientVarName = getClientVarName(facesContext, inputFile);
        String clientKey = inputFile.getClientKey();
        if (clientKey == null) {
            clientKey = clientVarName;
        }
        UIViewRoot viewRoot = facesContext.getViewRoot();
        Locale locale = viewRoot.getLocale();
        String formClientId = getParentFormClientId(inputFile);
        Application application = facesContext.getApplication();
        ViewHandler viewHandler = application.getViewHandler();
        String actionURL = viewHandler.getActionURL(facesContext, viewRoot.getViewId());
        String partialActionURL = facesContext.getExternalContext().encodePartialActionURL(actionURL);
        String namingContainerId = "";
        if (viewRoot instanceof NamingContainer) {
            namingContainerId = viewRoot.getContainerClientId(facesContext);
        }
        AjaxParameters ajaxParameters = new AjaxParameters(inputFile, clientId, formClientId);
        String execute = ajaxParameters.getExecute();
        String render = ajaxParameters.getRender();
        ExternalContext externalContext = facesContext.getExternalContext();
        I18n i18n = I18nFactory.getI18nInstance(externalContext);
        String notStartedMessage = i18n.getMessage(facesContext, locale, "not-started");
        JavaScriptFragment clientComponent = new JavaScriptFragment("Liferay.component('" + clientKey + "')");
        encodeFunctionCall(responseWriter, "LFAI.initProgressUploader", 'A', clientComponent, validContentTypes, clientId, formClientId, namingContainerId, inputFile.isAuto(), execute, render, partialActionURL, maxFileSize, notStartedMessage);
    } else // template and write it to the response.
    if (inputFile.isShowPreview()) {
        encodeFunctionCall(responseWriter, "LFAI.initPreviewUploader", 'A', validContentTypes, clientId, maxFileSize);
    }
}
Also used : Locale(java.util.Locale) ViewHandler(javax.faces.application.ViewHandler) InputFile(com.liferay.faces.alloy.component.inputfile.InputFile) ResponseWriter(javax.faces.context.ResponseWriter) NamingContainer(javax.faces.component.NamingContainer) ExternalContext(javax.faces.context.ExternalContext) JavaScriptFragment(com.liferay.faces.util.render.JavaScriptFragment) UIViewRoot(javax.faces.component.UIViewRoot) Application(javax.faces.application.Application) I18n(com.liferay.faces.util.i18n.I18n)

Example 5 with InputFile

use of com.liferay.faces.alloy.component.inputfile.InputFile in project liferay-faces-alloy by liferay.

the class InputFileRenderer method encodeMarkupBegin.

@Override
public void encodeMarkupBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    InputFile inputFile = (InputFile) uiComponent;
    // If the component should render the preview table or the upload progress table, then
    if (inputFile.isShowPreview() || inputFile.isShowProgress()) {
        // Start encoding the outermost <div> element.
        responseWriter.startElement("div", inputFile);
        String clientId = inputFile.getClientId(facesContext);
        responseWriter.writeAttribute("id", clientId, "id");
        RendererUtil.encodeStyleable(responseWriter, inputFile);
        // and write it to the response.
        if (inputFile.isShowProgress()) {
            encodeProgress(facesContext, responseWriter, inputFile, clientId);
        } else // Otherwise, delegate writing to the delegate renderer. Note that this effectively a no-op with Mojarra and
        // MyFaces, since they both delay writing of the entire <input type="file"...> ... </input> element until
        // encodeEnd.
        {
            super.encodeMarkupBegin(facesContext, inputFile);
        }
    } else // Otherwise, delegate writing to the delegate renderer. Note that this effectively a no-op with Mojarra and
    // MyFaces, since they both delay writing of the entire <input type="file"...> ... </input> element until
    // encodeEnd.
    {
        super.encodeMarkupBegin(facesContext, inputFile);
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) InputFile(com.liferay.faces.alloy.component.inputfile.InputFile)

Aggregations

InputFile (com.liferay.faces.alloy.component.inputfile.InputFile)6 ResponseWriter (javax.faces.context.ResponseWriter)3 FileUploadEvent (com.liferay.faces.alloy.component.inputfile.FileUploadEvent)1 I18n (com.liferay.faces.util.i18n.I18n)1 UploadedFile (com.liferay.faces.util.model.UploadedFile)1 JavaScriptFragment (com.liferay.faces.util.render.JavaScriptFragment)1 List (java.util.List)1 Locale (java.util.Locale)1 Application (javax.faces.application.Application)1 ViewHandler (javax.faces.application.ViewHandler)1 NamingContainer (javax.faces.component.NamingContainer)1 UIViewRoot (javax.faces.component.UIViewRoot)1 ExternalContext (javax.faces.context.ExternalContext)1