Esraa
Esraa

Reputation: 21

Primefaces fileUpload Listener does not invoked on wildfly server

I have added primeFaces fileUpload in my code and it worked fine on webLogic 12.2 server But when I changed the server to wildFly 10.0.1 the fileUpload Listener does not invoked anymore I wondered what is the reason and searched for this issue without avail.

That is the filters in web.xml

<filter>
   <filter-name>PrimeFaces FileUpload Filter</filter-name>
   <filter-class>org.primefaces.webapp.filter.FileUploadFilter
   </filter-class>
</filter>
<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

And that is my xhtml code

<p:column headerText="#{msgs.label_uploadFile}" >
    <p:fileUpload id="upload" label="#{msgs.label_uploadFile}" 
     fileUploadListener="#{attachmentsInquiryBean.handleFileUpload}" 
     mode="advanced" auto="true"/>
</p:column>

That is the Listener function

public void handleFileUpload(FileUploadEvent event) {
  // do something
 }

Also I added two jars in my wWEB-INF/lib folder called:

commons-fileupload-1.3.jar

commons-io-2.4.jar

Upvotes: 2

Views: 2331

Answers (3)

thogau
thogau

Reputation: 23

I had the same problem on tomcat and solved it by adding allowCasualMultipartParsing="true" in META-INF/context.xml :

<Context allowCasualMultipartParsing="true">
</Context>

Hope it helps.

Upvotes: 0

Sascha Buchner
Sascha Buchner

Reputation: 1

I've seen the same in Wildfly 10.x with PF 6.1.

The method expression for fileUpload.getFileUploadListener() is null on Wildfly.

My workaround is to use a binding on the FileUpload component and manually setting a valid method expression.

Upvotes: 0

ArgaPK
ArgaPK

Reputation: 455

Here is an example of how to upload a file using primefaces and you do not need commons-fileupload-1.3.1.jar and commons-io-2.4.jar; and also you do not need to change web.xml , for more information see this How to upload file in primefaces

java code:

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import org.primefaces.model.UploadedFile;
@ManagedBean
public class FileUploadView {
    private UploadedFile file;
    public UploadedFile getFile() {
        return file;
    }
    public void setFile(UploadedFile file) {
        this.file = file;
    }
    public void upload() {
        if(file.getSize() > 0) {
            FacesMessage message = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
            FacesContext.getCurrentInstance().addMessage(null, message);
        }
else{
    FacesMessage message = new FacesMessage("Not Succesful", "file is not uploaded");
            FacesContext.getCurrentInstance().addMessage(null, message);
}
    }
}

xhtml code:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
<h:form enctype="multipart/form-data">
    <p:growl id="messages" showDetail="true" />

    <p:fileUpload value="#{fileUploadView.file}" mode="simple" skinSimple="true"/>

    <p:commandButton value="Submit" ajax="false" actionListener="#{fileUploadView.upload}" />
</h:form>
  </h:body>
</html>

Upvotes: 0

Related Questions