The <tc:file/>
create a textfield with a choose directory button on the
right.
To load up files to the server for JSF 2.0 and 2.1 you will need to add a multipart-config entry to the
FacesServlet in the web.xml
file. Since JSF 2.2 this is not required.
Here you can configure some more general information.
<multipart-config>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<location>/tmp</location>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>
If using Servlet API 3.1 you may call part.getSubmittedFileName()
, for 3.0 you may use the Utility
org.apache.myfaces.tobago.internal.util.PartUtils.getSubmittedFileName(part)
to access to filename of the upload.
<tc:file label="Upload" value="\#{uploadController.file1}"/>
You can filter files using the <tc:validateFileItem/>
tag within
the <tc:file/>
.
In the following example only images and PDF files are excepted.
You can upload multiple files in one selection and request.
Use the multiple="true"
attribute.
Ajax can be activated by adding <f:ajax/>
to the <tc:file/>
tag.
The Ajax feature of file upload currently works with JSF 2.2 only!