Search code examples
jsffile-uploadprimefacesgraphicimage

Open file browse panel of p:fileUpload on click of an image


Is there any way to fire the basic <p:fileUpload> button (the one that shows a panel to select a file) on click of an image?


Solution

  • Just put the image in a label referring the input field.

    <h:form>
        <p:fileUpload id="file" mode="simple" ... />
        <h:outputLabel for="file">
            <p:graphicImage name="images/pic.png" />
        </h:outputLabel>
    </h:form>
    

    Do note that this works even if the input is hidden by CSS.

    See also: