Question

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>
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top