I need to upload a file using <h:inputFile>
. I am using the following code:
<h:inputFile id="inputFile" value="#{bean.uploadedFile}" styleClass="hidden">
<f:ajax listener="#{bean.processFile}"/>
</h:inputFile>
...
<button onclick="$('#inputFile').click();">
Choose file
</button>
As you can see, I am hiding the ugly <h:inputFile>
and just simulating a click on it using a button.
When I click the button, the file explorer is shown and I can choose a file, but, once selected, the page reloads and the processFile
method is never called.
If I remove the hidden class for the <h:inputFile>
, click on it and select a file, everything works perfectly.
I tried simulating the click with the <h:inputFile>
visible, but the same wrong behavior occurs.
Is there anything I can do to simulate the click and retain the <h:inputFile>
hidden.
I am using Wildfly with JSF 2.3.
Thanks