0

This is in reference to the following thread [File upload doesn't work with AJAX in PrimeFaces 4.0/JSF 2.2.x - javax.servlet.ServletException: The request content-type is not a multipart/form-data

The problem I experience is Nullpointer on clicking the command button.

Starting from the web.xml

<context-param>
    <param-name>primefaces.UPLOADER</param-name>
    <param-value>commons</param-value>
</context-param>

xhtml

<p:fileUpload id="file" value="#{userBean.uploadedFile}"
                    mode="simple" required="true" allowTypes="*.xls,*.xlsx"
                    requiredMessage="#{msg.vrUserUpload}"
                    invalidFileMessage="#{msg.vrUserUploadInvalidFile}"
                    multiple="false" fileUploadListener="userBean.fileUploadListener" />

<p:commandButton id="btnUpload" value="#{displayText.btUpload}"
                        styleClass="button_lite" actionListener="#{userBean.insert}"
                        ajax="true" update="userMassUploadForm"
                        process="userMassUploadForm">
                    </p:commandButton>

UserBean.java

public void fileUploadListener(FileUploadEvent event)
    {
        uploadedFile = event.getFile();
    }

    public void insert(){
         if(uploadedFile!=null){
                System.out.println(uploadedFile.getFileName());
            }
            else{
                System.out.println("The file object is null.");
            }
    }

Console prints out "The file object is null." whenever ajax="true" and when set to false, works. I could not find a solution for this in the above referred thread. Please advise.Also please let me know if you want any further information.

Community
  • 1
  • 1
venki
  • 29
  • 1
  • 4

1 Answers1

0

From PrimeFaces user guide:

Simple File Upload

Simple file upload mode works in legacy mode with a file input whose value should be an UploadedFile instance. Ajax uploads are not supported in simple upload.

Community
  • 1
  • 1
Jaqen H'ghar
  • 4,305
  • 2
  • 14
  • 26
  • The purpose is to upload the excel file with data. This data is then validated with some rules against the database master table entries. If not, those messages should be captured and shown in p:messages. Please suggest any way by which this can be accomplished. – venki Mar 19 '15 at 14:48
  • I'd think you at least need mode="advanced" for the ajax to work. If there are still problems there are many answers to problems with fileupload already on the site. – Jaqen H'ghar Mar 25 '15 at 06:27