| Manorrock.com / Products / Manorrock JSF Upload |
The UploadListener is used to make sure the FacesServlet knows about an uploaded file.
Even though we envision that users will use the inputFile component in conjuction with the UploadListener it is not required. The sample below shows you how easy it is to have it in a JSF form.
<h:form enctype="multipart/form-data">
<input type="hidden" name="upload" value="false"/>
File to add: <input size="32" type="upload_file" name="file"/> <br/>
<h:commandLink action="#{fileAddBean.doAdd}" value="Add"/>
</h:form>In your back-end code you will then have access to it using the following code snippet.
byte[] file = FacesContext.getCurrentInstance().
getExternalContext().getRequestMap().get("upload_file");Using the upload:inputFile component is obviously what this library is all about. The page snippet below shows you how easy it really is in JSF.
<h:form enctype="multipart/form-data">
File to add: <upload:inputFile
xmlns:upload="http://www.manorrock.com/jsf/upload"
value="#{bean.data}"/> <br/>
<h:commandLink action="#{bean.upload}" value="Upload"/>
</h:form>In your back end code this would map to a field of type byte[] on your managed bean. Note make sure you have the getters and setters for the variable.