Search code examples
jqueryfile-uploadjsf-2xhtmlrichfaces

RichFaces FileUpload without Add Button and call by commandLink


I am using Richfaces 4 fileupload to upload one file.

But in my case i just want to click in one link and see the browser to select the file.

So in my code i have commandLink:

<a4j:commandLink id="showFileUpload"
                    execute="@this"
                action="#{doSomething.Something(a)}"
                render="@none" 
                oncomplete="#{rich:element('stratFileUpload')}.click();"
                >
                <h:graphicImage value="/images/A.png" />
            </a4j:commandLink>

And the part of the fileUpload is just a form with the fileUpload on it:

<h:form id="stratFileUploadForm">
    <rich:fileUpload id="stratFileUpload" execute="@this"
        fileUploadListener="#{doUploadedFile}"
        onuploadcomplete="
                                    jQuery(#{rich:element('stratFileUpload')}).find('.rf-fu-itm-lnk').click();
                                    "
        noDuplicate="true" maxFilesQuantity="1"
        sizeExceededLabel="#{msg['sizeExceeded']}"
        uploadLabel="#{msg['upload']}" />
</h:form>

I already call in the commandLink the id form and rich:fileUpload id but nothing works.

The only way for this to work is with popup, and in that case it came with the "+ Add" button.


Solution

  • The problem was because of the the upload browser as been block by the Chrome, in the Chrome i can't access the browser to choose the files, but in the IE, Edge and Firefox i can see that browser. Chrome block the browser files (popup), because of the time between the action and the oncomplete

    This part of the code:

     <a4j:commandLink id="showFileUpload"
                         execute="@this"
                     action="#{doSomething.Something(a)}"
         ...
                 </a4j:commandLink>