I have an application that was built on JSF 2.0.
Now I need to create an upload functionality to it.
I'm using Tomahawk as described by @BalusC in this post:
The problem is that after choosing the file and clicking submit, it gets to the submit method but the uploadedFile object is null in the first line.
Why doesn't it contain the file content?
Here is the code.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="templates/TemplateDefault.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:t="http://myfaces.apache.org/tomahawk">
<ui:define name="content">
<h:form prependId="false" id="myForm">
<t:inputFileUpload value="#{myControlBean.uploadedFile}" />
<h:commandButton value="submit" action="#{myControlBean.submit}" />
<h:messages />
</h:form>
</ui:define>
</ui:composition>
Java class:
private UploadedFile uploadedFile;
public void submit() throws IOException {
String fileName = FilenameUtils.getName(uploadedFile.getName());
...
}
public UploadedFile getUploadedFile() {
return uploadedFile;
}
public void setUploadedFile(UploadedFile uploadedFile) {
this.uploadedFile = uploadedFile;
}