When I upload a file in jsf 2.2 project with jboss 7.1 its prevent to submit form. help me out....
here is sample code for upload a file
This is my welcome.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
</h:head>
<h:body>
<h:form enctype="multipart/form-data" >
<h:outputLabel value="Upload File : " />
<h:inputFile value="#{myController.file}"/>
<h:commandButton value="Submit" action="#{myController.mycontroller}" />
</h:form>
</h:body>
</html>
Here is my backing bean MyController.java
public class MyController {
private Part file;
public Part getFile() {
return file;
}
public void setFile(Part file) {
this.file = file;
}
public String mycontroller() throws IOException {
System.out.println("--call mycontroller method--");
UploadFile uf = new UploadFile();
boolean b = uf.upload(getFile());
System.out.println(b);
return "success.xhtml";
}
}
Edit:1
I have one form with file upload and a <h:commandButton>
, where I want to get uploaded file's information. Problem I am facing, the button is not firing when I added enctype="multipart/form-data"
. So any advice will be helpful to me.