1

First of all, I have to say, that I've read all (at least a lot :)) questions here and on primefaces forums about fileuploader issues.

My configuration:

Primefaces 4

JSF 2.2

Spring

Apache Tomcat 7

Maven

I am converting a richfaces project to primefaces, and I'm stuck with a fileUpload component that is not calling the handler method.

I have tried (altough I know that from Primefaces 4 it is not necessary) putting filters in the web.xml. I've also tried without filters. I have spring security filters and a language filter among some others, but the PF was first. I've also tried setting the dispatcher to FORWARD.

I have all the needed dependecies in Maven (commons - I know that from version 4 it is not required, but nevertheless I tried)

The xhtml part:

<h:form enctype="multipart/form-data">

        ... /* not relevant code here */ ...

                            <p:graphicImage value="#{systemParamsController.image}"
                                id="logo" />

                            <p:fileUpload
                                fileUploadListener="#{systemParamsController.listener}"
                                fileLimit="1" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
                                uploadLabel="#{msg['button.upload.jpg']}"
                                cancelLabel="#{msg['button.cancel']}"
                                invalidFileMessage="alert('#{msg['upload.invalidtype']}');"
                                update="logo" mode="advanced">
                            </p:fileUpload>
                            <p:growl id="messages" showDetail="true" />
                        </h:panelGrid>
                    </h:panelGroup>
                    <p:commandButton value="#{msg['button.save']}" onclick="this.disabled=true"  oncomplete="this.disabled=false"
                        action="#{systemParamsController.save}" styleClass="qs-button"
                        ajax="false" />
                </h:panelGrid>
            </p:panel>
        </center>
    </h:form>

The backing bean:

public synchronized void listener(FileUploadEvent event) throws Exception {
  logger.debug("uploadListener!");
  UploadedFile item = event.getFile();
  getModel().getCustomer().setLogo(imageResizer.doResize(item.getContents(), 30, Side.HEIGHT));
}

If I click on choose, I can select a file, but after that nothing happens. The handler is not called, because there is no log message, the upload file button is inactive. I have used this component before for more complex issues without problem, so I'm sure I'm missing something obvious.

Thanks in advance for any kind of help!

omniflash
  • 191
  • 1
  • 14
  • 1
    Open you favorite Javascript console...is it giving any meaningful error? What is the scope of you backing bean? – elbuild Jan 08 '14 at 13:52
  • :) Cant express my thanks enough for the js console hint...There was a syntax error in the substituted text in the invalidFileMessage... Thank you so much! – omniflash Jan 08 '14 at 14:35

1 Answers1

0

Make sure you have the PrimeFaces FileUpload Filter as the first filter in your 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>

If you're having trouble with the default primefaces uploader you can try the commons fileupload:

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

We're using this Maven dependency:

<dependency>
   <groupId>commons-fileupload</groupId>
   <artifactId>commons-fileupload</artifactId>
   <version>1.3.1</version>
</dependency>

Also, try putting the file upload in its own form.

awilkinson
  • 1,601
  • 15
  • 23