Execute Upload Files Primefaces from External EventAction like button , link

StackOverflow https://stackoverflow.com/questions/23583423

  •  19-07-2023
  •  | 
  •  

문제

i have to create input form with attachment , so i want to execute file uploading in Submit button only so it will insert data into database and upload the files also ... i have searched and i didn't find any simple answer... thanks in advance image below https://i.stack.imgur.com/CX4dc.png

i have tried to call upload event in button and disable ajax but it failed

<h:form enctype="multipart/form-data">
    <p:panel header="Upload Files">
        <p:fileUpload fileUploadListener="#{uploadbean.upload}"
                      update=":aform"  allowTypes="/(\.|\/)(gif|jpe?g|png|pdf|doc|docx)$/" sizeLimit="30000000" />
    </p:panel>

    <p:commandButton ajax="false" action="#{uploadbean.upload}" value="Upload Files" />
</h:form>
도움이 되었습니까?

해결책

please check Primeface's example

<h:form enctype="multipart/form-data">
    <p:messages showDetail="true"/>
    <p:fileUpload value="#{fileUploadController.file}" mode="simple"/>
    <p:commandButton value="Submit" ajax="false"
                actionListener="#{fileUploadController.upload}"/>
</h:form>

in your bean:

public void upload() {
        if(file != null) {
            FacesMessage msg = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }

it's available at: http://www.primefaces.org/showcase/ui/fileUploadSimple.jsf . you can find different file uploader at the left sidebar in "File" part. good luck

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top