Reply To: Command not fired with multipart form (JSF 2.2)

Splash Forums PrettyFaces Users Command not fired with multipart form (JSF 2.2) Reply To: Command not fired with multipart form (JSF 2.2)

#26842

Gianluca Elmo
Participant

Hi,

I have just tested my application again and it works as expected.

For your information I am running Wildfly 8.2.0, PF 5.1.9, Rewrite 2.0.12 and some more other things, which I do not believe are of any relevance for you.

To test it I have uploaded a zip file into the /tmp directory and unpacked it and a .jpf file.

Here the uploadManager (sorry for the not so nicely written code)

/**
* Manage the upload of a zip file into a fixed directory.
*
* @param event – the event related to the upload of the file.
*/
public void fileUploadManager(FileUploadEvent event) {
try {
File targetFolder = new File(“/tmp/FileUpload”);
InputStream inputStream = event.getFile().getInputstream();
OutputStream out = new FileOutputStream(new File(targetFolder, event.getFile().getFileName()));
int read = 0;
byte[] bytes = new byte[1024];

while ((read = inputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
inputStream.close();
out.flush();
out.close();

FacesMessage msg = new FacesMessage(“Succesful”, event.getFile().getFileName() + ” is uploaded.”);
FacesContext.getCurrentInstance().addMessage(null, msg);

// Unzip the file
unzip(“/tmp/FileUpload/” + event.getFile().getFileName(), “/tmp/FileUpload”);
//ief.loadDataFromFile(targetFolder.getPath(), event.getFile().getFileName());
} catch (IOException e) {
e.printStackTrace();
}
}

Here the client side
<h:form>
<p:outputLabel value=”Manuals upload” for=”manualsUploadFULst”/>
<p:fileUpload id=”manualsUploadFULst” fileUploadListener=”#{ditProSBean.fileUploadManager}” mode=”advanced” auto=”false”
allowTypes=”/(\.|\/)(zip|png|jpg)$/” multiple=”true”
cancelLabel=”#{msgs.cancel}” uploadLabel=”#{msgs.upload}” label=”#{msgs.choose}”/>
</h:form>

I have noticed that in your code you are using filters and servlet multipart I do not have in my web.xml

<filter>
<filter-name>OCPsoft Rewrite Filter</filter-name>
<filter-class>org.ocpsoft.rewrite.servlet.RewriteFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>OCPsoft Rewrite Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ASYNC</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>

<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>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>

<multipart-config>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>

Hope it can help you somehow.

  • This reply was modified 6 years, 12 months ago by  Gianluca Elmo.