I'm trying to get the primefaces fileupload to work without success.
For help I use the 'simple' fileupload showcase . http://www.primefaces.org/showcase-labs ... Simple.jsf
The problem is that when the upload method get's called, the field codaFile is still null.
I tried methods with FileUploadEvent + listeners on the fileUpload component as well as making the controller session scoped.
I'm using primefaces 3.0.M2.
Please do not ask me to use a newer version because that is not an option for the time being.
If it's not possible, I will have to implement my own file upload component.
I have both commons-io 1.4 and commons-fileupload 1.2.1
Thank you in advance,
Nico
upload.jsp
Code: Select all
<h:form enctype="multipart/form-data">
<p:messages showDetail="true"/>
<p:fileUpload id="codaFileToUpload" value="#{fileUploadController.codaFile}" mode="simple"/>
<p:commandButton value="Submit" ajax="false" actionListener="#{fileUploadController.upload}"/>
</h:form>
Code: Select all
@ManagedBean(name = "fileUploadController")
@RequestScoped
public class FileUploadControllerBean implements Serializable {
private UploadedFile codaFile;
/**
* @return the codaFile
*/
public UploadedFile getCodaFile() {
return codaFile;
}
/**
* @param codaFile the codaFile to set
*/
public void setCodaFile(UploadedFile codaFile) {
this.codaFile = codaFile;
}
/**
* Upload a coda file.
*/
public void upload() {
FacesMessage msg;
try {
new CodaFileReader(codaFile.getFileName(), codaFile.getInputstream());
} catch (IOException e) {
// TODO
}
msg = new FacesMessage("Succesful", codaFile.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
Code: Select all
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>