I am using Primefaces 6, JSF 2.2, NetBeans and GlassFish
My problem is that fileUploadListener doesn't execute my Bean's function. I think I may have a problem with Listener calls, but I'm using JSF 2.2 and I've read that I don't need to configure anything in web.xml.
My .xhml code
<h:form id="formItem1" enctype="multipart/form-data">
<p:dialog header="Upload Files" widgetVar="newFileDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
<p:outputPanel id="newFileDetail" style="text-align:center;">
<f:facet name="header1">
<p:graphicImage library="resources" name="images/document.png"/>
</f:facet>
<BR />
<p:fileUpload fileUploadListener="#{itemBean.upload}" auto="true"/>
<BR />
<BR />
<p:commandLink id="createItembtn" action="#{catalogBean.addItem()}">
<p:graphicImage library="resources" name="images/upload.png" style="width: 50; height: 50"/>
</p:commandLink>
</p:outputPanel>
</p:dialog>
</h:form>
My itemBean.java code
public void upload(FileUploadEvent event) {
try{
if(file != null) {
File tempFile=new File("auxUL"); if ( ! tempFile.exists() ) { tempFile.createNewFile(); }
InputStream fileIn = new FileInputStream(tempFile);
fileIn = event.getFile().getInputstream();
fileIn.close();
tempFile.deleteOnExit();
file.getInputstream();
List<File> files = new ArrayList<File>();
files.add(tempFile);
userManagerItem.admCatalog.uploadFilesToItem(userManagerItem.getSelectedCatalog(), itemSelec, files);
FacesMessage message = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
tempFile.deleteOnExit();
}
}catch(Exception e){
FacesMessage message = new FacesMessage("Failed", file.getFileName() + " is not uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
Thanks in advance, if you have any questions ask. Thank you
Try putting the fileupload inside a form It seems to me that what you are doing is fine, but try this way.