I added an <h:messages/> tag and there are none - I haven't plugged in any validation yet anyway. I redid a clean example (ie. vanilla myfaces/tomahawk) to be sure I wasn't wasting your time. ;-)

<!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:f="http://java.sun.com/jsf/core";
     xmlns:h="http://java.sun.com/jsf/html";
     xmlns:ui="http://java.sun.com/jsf/facelets";
     xmlns:c="http://java.sun.com/jstl/core";
xmlns:t="http://myfaces.apache.org/tomahawk"; xmlns:afh="http://xmlns.oracle.com/adf/faces/html";
     xmlns:af="http://xmlns.oracle.com/adf/faces";
   >

   <ui:composition id="fu">
       <h:form id="fu3" name="form1" enctype="multipart/form-data" >
           <h:outputText id="fu4" value="Please give me an image"/>
           <t:inputFileUpload id="fileupload"
                              accept="image/*"
                              value="#{myModel.file}"
                              storage="file"
                              required="true"/>
<h:commandButton id="fu5" value="Upload Now!" action="#{myModel.doUpload}" />
       </h:form>
       <h:messages/>

   </ui:composition>
</html>

From my console (my own phase listener debug):

===============< phase RESTORE_VIEW(1)>===========
===============< phase APPLY_REQUEST_VALUES(2)>===========
===============< phase PROCESS_VALIDATIONS(3)>===========
===============< phase UPDATE_MODEL_VALUES(4)>===========
===============< phase INVOKE_APPLICATION(5)>===========
MyModel 1
MyModel 3 null

My full model class is as below:

/*
* Created on Feb 13, 2006
*/
package com.playpen.ncs.aui.model;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;

import org.apache.myfaces.custom.fileupload.UploadedFile;

/**
* @author Murray
*/
public class MyModel
{
private UploadedFile _file; public void processAction(ActionEvent e) throws AbortProcessingException
   {
System.out.println("MyModel: triggered with processAction event=" + e.getComponent().getId());
   }

   /**
    * To support file upload
    * @param event
    */
   public void fileUploaded(ValueChangeEvent event)
   {
       System.out.println("MyModel 0");
       UploadedFile file = (UploadedFile)event.getNewValue();
       if (file != null)
       {
           System.out.println("MyModel fileUploaded called with a file");
           FacesContext context = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage("Successfully uploaded file " + file.getName() + " (" + file.getSize() + " bytes)"); context.addMessage(event.getComponent().getClientId(context), message);
           // Here's where we could call file.getInputStream()
       }
       else
       {
           System.out.println("MyModel fileUploaded called with no file");
       }
   }
public UploadedFile getFile()
   {
       System.out.println("MyModel 1");
       return _file;
   }

   public void setFile(UploadedFile file)
   {
       System.out.println("MyModel 2");
       _file = file;
   }

   public String doUpload()
   {
       UploadedFile file = getFile();
       System.out.println("MyModel 3 " + file);
       // ... and process it in some way
       return (file != null ? file.getName() : null);
   }
}

Reply via email to