在jsf

时间:2018-01-04 11:15:15

标签: jsf primefaces

你好,请任何人帮助我,我试图上传文件在prime-faces文件上传事件与高级模式和自动真实,但我的文件将保存,当我点击保存按钮自动真仅将保存在我的文件列表,但自动为true我无法向用户显示他/她选择的文件。

这是图片image

这里是xhtml:

<h:form enctype="multipart/form-data">

                                            <p:dataTable id="flName" var="obj" value="#{empRegManagedBean.allRequiredDocuments}"
                                                         paginatorPosition="bottom" rowIndexVar="row" reflow="true" rows="10"
                                                         paginator="true">
                                                <p:column  headerText="S#" style="width:36px">
                                                    <h:outputText value="#{row+1}"/>
                                                </p:column>
                                                <p:column headerText="File Name" style="width: 30%">
                                                    <h:outputText value="#{obj.documentTitle}" />
                                                </p:column>
                                                <p:column headerText="Required " style="width: 10%">
                                                    <h:outputText value="#{obj.required eq true? 'YES' : 'NO'  }" />
                                                </p:column>
                                                <p:column headerText="Submitted" style="width: 10%" rendered="#{empRegManagedBean.employeeObj.employeeId > 0}">
                                                    <h:outputText value="#{obj.submitted eq true? 'YES' : 'NO'  }"/>
                                                </p:column>
                                                <p:column headerText="Upload " style="width: 20%">
                                                    <p:fileUpload   
                                                        fileUploadListener="#{empRegManagedBean.fileUpload}"    
                                                        multiple="false" auto="true"  update="flName" sizeLimit="1000000" allowTypes="/(\.|\/)(docx|jpe?g|png|pdf|xlsx|txt)$/" >
                                                        <f:attribute name="docID" value="#{obj.documentId}" />
                                                        <f:attribute name="doctitl" value="#{obj.showtitle}" />

                                                    </p:fileUpload>

                                                </p:column>

                                                <p:column headerText="Download" style="width: 30%" rendered="#{empRegManagedBean.employeeObj.employeeId > 0}">

                                                    <h:outputLink rendered="#{obj.documentTitle ne null}"  value="../../Upload_companyLogo/#{obj.documentTitle}">
                                                        <img src=""  alt="#{obj.documentTitle}" align="top"/>

                                                    </h:outputLink>
                                                </p:column>




                                            </p:dataTable>
                                        </h:form>

以下是托管Bean:

     public void fileUpload(FileUploadEvent event) {
 event.getComponent().getAttributes().get("docID");
    this.globalevents.add(event);
    System.out.println("Event " + event.getFile().getFileName());
    try {


        count++;
        System.out.println("Change properties occures" + event);
        String path = FacesContext.getCurrentInstance().getExternalContext()
                .getRealPath("/");
        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss");
        String name = fmt.format(new Date()) + "_" + event.getFile().getFileName();

        if (!(event.getFile().getFileName().contains(this.employeeObj.getEmployeeCode()))) {
            documentFileType = this.employeeObj.getEmployeeCode() + "_" + count + "_" + event.getFile().getFileName();
            docID = (Integer) event.getComponent().getAttributes().get("docID");
            showTitle = (String) event.getComponent().getAttributes().get("doctitl");
            System.out.println("Document Id : " + docID);
            System.out.println("showTitle : " + showTitle);
        }

        if (event.getFile().getFileName() != null) {
            FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
            FacesContext.getCurrentInstance().addMessage(null, message);
        }

        tempPath = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("fileUplodDirectory");
        docsFiles = new File(tempPath + documentFileType);
        HRMFile f = new HRMFile();
        f.setDocFile(docsFiles);
        f.setEvent(event);
        f.setFileName(docsFiles.getName());
        f.setDocumentId(docID);
        f.setPath(tempPath);
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(System.currentTimeMillis());
        f.setUploadedDateTime(c.getTime());
        f.setVtmsTypeCode(1);
        f.setType(name.substring(name.lastIndexOf(".")));
        System.out.println(tempPath);
        System.out.println(tempPath);
        if (attachedFiles == null) {
            attachedFiles = new ArrayList();
        }
        attachedFiles.add(f);


    } catch (Exception ex) {
        Logger.getLogger(EmpRegisterManagedBean.class.getName()).log(Level.SEVERE, null, ex);
    }
}

0 个答案:

没有答案