0

the fileUploadListener method is not fired. I'm using code from the Primefaces showcase:

Here is my jsf code:

  <h:form enctype="multipart/form-data">
    <p:fileUpload mode="simple" value="#{uploadBean.file}" />
    <p:commandButton value="Upload" action="#{uploadBean.upload}" ajax="false" />
</h:form>

Here is my bean code:

@ManagedBean(name="uploadBean")
public class UploadBean {


     private UploadedFile file;

        public UploadedFile getFile() {
            return file;
        }

        public void setFile(UploadedFile file) {
            this.file = file;
        }

       public void upload() {


        System.out.println("--->tipofile"+ file);
        if(file != null) {
            FacesMessage message = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
            FacesContext.getCurrentInstance().addMessage(null, message);
        }
    }

Is there anything wrong? I haven't configured any xml as I'm currently using Primefaces 5.2

EDIT: The same question was asked before. As noone of the answers solves my problem, I thought that maybe it has to do with the PF version I'm using How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null

EDIT2: Trying debugging as suggested in the duplicated question I note: The Network section is fine. FileUploadRenderer#decode() is not called. My Upload() method is not called with enctype="multipart/form-data". I'll now try to see why upload is not called with enctype="multipart/form-data".

Community
  • 1
  • 1
Gyonder
  • 3,674
  • 7
  • 32
  • 49
  • Do you have h:head, h:body etc.? Seems to me you should have a scope on the bean – Jaqen H'ghar Jun 23 '15 at 17:58
  • 1
    As per your edit, your code still shows problems which are solved in the duplicate question. You also did nowhere explicitly mention/confirm the other prerequirements mentioned in the duplicate question. In other words, nothing of this question gave the impression that you read and understood the duplicate question. – BalusC Jun 24 '15 at 07:24
  • Actually I made several attempts. Now I matched the code with the duplicate question. But stilll the upload method isn't called. I've tried adding the filters even if I'm on servlet 3 jsf 2.2. If you have any advice please let me know – Gyonder Jun 24 '15 at 08:05
  • At the very bottom of the top answer of the duplicate question you can find debug hints. Please include detail of those debugs/observations in your question. – BalusC Jun 24 '15 at 08:11
  • #BalusC I added some info from debug in Edit2. If you have any idea about what's wrong, please let me know – Gyonder Jun 24 '15 at 08:37
  • Which JSF impl/version? What exactly do you mean with *"Upload is not called with enctype="multipart/form-data"* ? Do you mean that request content type is not multipart/form-data (as seen in Network section)? Does the `` work? (i.e. `xmlns:h` is properly declared and it generates the desired HTML output) – BalusC Jun 24 '15 at 09:29
  • I'm using Mojarra 2.2.6. I meant that my upload() method is not executed with -. With works fine, but of course I don't need it now. – Gyonder Jun 24 '15 at 09:39
  • Works just fine for me with Mojarra 2.2.6 (and current 2.2.11) and PrimeFaces 5.2 on Tomcat 8.0.23. Your problem is therefore still not visible in the information provided so far. Perhaps you're not testing in a completely blank project with only the provided code? Perhaps you're using a template and nesting forms? Etc. Creating a real MCVE should give clues. – BalusC Jun 24 '15 at 11:37
  • Ok, I'm using on IBM Websphere 8. No nesting forms or template. Anyway, I'll try a completely blank project as you advise. – Gyonder Jun 24 '15 at 12:53

0 Answers0