I am trying to upload a file with a simple form, but it just returns to the same page all the time. To find an error or something wrong, I just want to write the name of the downloaded file in the output. As soon as I can get the file name, I think I can handle how to handle the whole file. So this is my code:
<h:form enctype="multipart/form-data"> <h:outputText value="Argazkia: "/> <p:fileUpload value="#{jokoBerriaController.file}" mode="simple"/> <p:commandButton value="Bidali" ajax="false" actionListener="#{jokoBerriaController.upload()}"/> </h:form>
Controller:
import javax.faces.bean.ManagedBean; import org.primefaces.model.UploadedFile; @ManagedBean public class jokoBerriaController { public static UploadedFile file; public UploadedFile getFile() { return file; } public void setFile(UploadedFile file) { this.file = file; } public void upload() { System.out.println("file " + file.getFileName()); } }
I added
<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>
in my web.xml file, but I did not add commons-io and commons-fileupload libraries. I read that I need to put the following code in my pom.xml file, but I can not find this file.
<dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>1.4</version> </dependency>
Thank you for your help.
PD: Sorry for my English.
java file-upload jsf primefaces
ferpinan
source share