1 Reply Latest reply on Dec 15, 2016 5:13 AM by Michal Petrov

    Rich faces File Upload not working on using custom FileUploadEvent

    New User Newbie

      0dowvotefavorite

       

       

      We want to customise org.richfaces.event.FileUploadEvent to cater to one of our application needs. I have extended above class as CustomFileUploadEvent and checking to see if the corresponding object is getting instantiated(entering constructor) on calling fileUploadListener="#{fileUploadBean.uploadListener}" using rich faces file upload tag.

      <rich:fileUpload id="upload" fileUploadListener="#{fileUploadBean.uploadListener}" immediateUpload="true" addControlLabel="Add" >
      <a4j:ajax event="uploadcomplete" execute="@none" onbegin="disableButtons()"
      oncomplete="enableButtons()" /> </rich:fileUpload>
      

       

      CustomFileUploadEvent.java file:

      import javax.faces.component.FacesComponent;
       import javax.faces.component.UIComponent;
      
         
       @FacesComponent(value="CustomFileUploadEvent")
       public class CustomFileUploadEvent extends org.richfaces.event.FileUploadEvent {
      
      
          public CustomFileUploadEvent(UIComponent component, UploadedFile uploadedFile) {
          super(component, uploadedFile); // TODO Auto-generated constructor stub
      
          }
       }
      
      
      
      

       

      In FileUploadBean.java, We have below listener method. If We use richfaces FileUploadEvent, listener method gets called correctly. But if we use CustomFileUploadEvent, it throws javax.faces.event.AbortProcessingException

      //Doesn't work
       //   public void uploadListener(test.fileupload.CustomFileUploadEvent event) throws IOException{
      
          //Works
          public void uploadListener( org.richfaces.event.FileUploadEvent event) throws IOException{
      
          UploadedFile item = event.getUploadedFile(); UploadFile file= new UploadFile();
          file.setBytes(item.getData());
          ....
      
      
      
      

       

       

      Am I missing any configuration in faces-config.xml or in @FacesComponent annotation in CustomFileUploadEvent.java ?

        • 1. Re: Rich faces File Upload not working on using custom FileUploadEvent
          Michal Petrov Master

          I am not sure how you expect this to work, what are trying to do?

           

          @FacesComponent is an annotation for components and the listener doesn't work because the argument of the listener method has to be FileUploadEvent (and you shouldn't need to change it in the first place). Most importantly RichFaces doesn't know you have an extended event you want to use, if you want fileUpload to use your custom event you have to overwrite the methods that handle it.