How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null / throws an error / not usable

前端 未结 10 2368
孤独总比滥情好
孤独总比滥情好 2020-11-21 05:04

I\'m trying to upload a file using PrimeFaces, but the fileUploadListener method isn\'t being invoked after the upload finishes.

Here is the view:

10条回答
  •  你的背包
    2020-11-21 05:21

    bean.xhtml

            
    
                    
    
    
    

    Bean.java

    @ManagedBean
    

    @ViewScoped public class Submission implements Serializable {

    private UploadedFile file;
    
    //Gets
    //Sets
    
    public void uploadFasta(FileUploadEvent event) throws FileNotFoundException, IOException, InterruptedException {
    
        String content = IOUtils.toString(event.getFile().getInputstream(), "UTF-8");
    
        String filePath = PATH + "resources/submissions/" + nameOfMyFile + ".pdf";
    
        MyFileWriter.writeFile(filePath, content);
    
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO,
                event.getFile().getFileName() + " is uploaded.", null);
        FacesContext.getCurrentInstance().addMessage(null, message);
    
    }
    

    }

    web.xml

        
        Faces Servlet
        *.xhtml
    
    
        PrimeFaces FileUpload Filter
        org.primefaces.webapp.filter.FileUploadFilter
    
    
        PrimeFaces FileUpload Filter
        Faces Servlet
    
    

提交回复
热议问题