Primefaces fileUploadListener does not call / executes the function

2

I am using Primefaces 6, JSF 2.2, NetBeans and GlassFish

My problem is that fileUploadListener does not execute the function of my Bean. I think I may have a problem with the Listener calls, but I'm using JSF 2.2 and I've read that I do not need to configure anything from 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. Thanks

    
asked by Pablo García Tamarit 04.08.2016 в 14:17
source

1 answer

0

Try putting the fileupload in a form I think it's fine what you're doing, but you have a test like this.

  <h:form id="filterForm107Adjunto">
    <p:fileUpload auto="true" styleClass="fileUploadSimple"  label="Examinar..." cancelLabel="Cancelar" fileUploadListener="#{itemBean.upload}" uploadLabel="Subir" invalidSizeMessage="Archivo muy grande: " invalidFileMessage="Solo doc, docx, xls,xlsx y pdf: " id="idFIleUpload" mode="advanced" dragDropSupport="false" multiple="true" sizeLimit="1048576" allowTypes="/(\.|\/)(doc|docx|xls|xlsx|pdf)$/" /> 
</h:form>
    
answered by 05.10.2016 / 18:58
source