Jorge Rocha
Jorge Rocha

Reputation: 724

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.

Upvotes: 1

Views: 238

Answers (2)

Jorge Rocha
Jorge Rocha

Reputation: 724

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>

Upvotes: 0

Makhiel
Makhiel

Reputation: 3884

Are you sure it's RichFaces 2.0?

Clicking on the fileUpload does nothing (just like if you click manually). You have to click on the file input, e.g.

$(".rf-fu-btn-cnt-add input").click()

but I'm not sure if all browsers let you do that when the button is hidden.

Upvotes: 1

Related Questions