Fileupload Component not working
Posted: 14 Oct 2011, 14:27
anybody help me i serve a lot but did not find any solution about file upload component
i am using simple fileupload component from http://www.primefaces.org/showcase-labs ... Simple.jsf
my abc.xhtml page is
<h:form enctype="multipart/form-data">
<p:messages showDetail="true"/>
<p:fileUpload value="#{test.file}" mode="simple"/>
<p:commandButton value="Submit" ajax="false"
actionListener="#{test.upload}"/>
</h:form>
my bean is with session scop
and i am using primefaces.3.0.M3 version
private UploadedFile file;
public UploadedFile getFile() {
System.out.println("getter");
return file;
}
public void setFile(UploadedFile file) {
System.out.println("setter");
this.file = file;
}
public String upload() {
try{
System.out.println("calling upload");
FacesMessage msg = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}catch(Exception e){
System.out.println("calling upload "+ e.getMessage());
}
return null;
}
show Nullpointer Exception
because file object not setted when submit button press
kindly anybody tell me what is going wrong in the above code or is there any additional code is required
i am using simple fileupload component from http://www.primefaces.org/showcase-labs ... Simple.jsf
my abc.xhtml page is
<h:form enctype="multipart/form-data">
<p:messages showDetail="true"/>
<p:fileUpload value="#{test.file}" mode="simple"/>
<p:commandButton value="Submit" ajax="false"
actionListener="#{test.upload}"/>
</h:form>
my bean is with session scop
and i am using primefaces.3.0.M3 version
private UploadedFile file;
public UploadedFile getFile() {
System.out.println("getter");
return file;
}
public void setFile(UploadedFile file) {
System.out.println("setter");
this.file = file;
}
public String upload() {
try{
System.out.println("calling upload");
FacesMessage msg = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}catch(Exception e){
System.out.println("calling upload "+ e.getMessage());
}
return null;
}
show Nullpointer Exception
because file object not setted when submit button press
kindly anybody tell me what is going wrong in the above code or is there any additional code is required