2 Replies Latest reply on May 30, 2014 1:35 PM by lucas-souza

    fileUploadListener is not being called

    ericute

      Hi,

       

      I am developing a code with libraries:

      • richfaces-api-3.3.3.Final.jar
      • richfaces-impl-3.3.3.Final.jar

       

      I want to use <rich:fileUpload>, however, the method i put in the fileUploadListener attribute is not being called. What would be the cause of this?

       

      Here are snippets of my code:

       

      FileUploadBean

      public class FileUploadBean {

       

          private List<File> files = new ArrayList<File>();

          private int uploadsAvailable;

          private boolean autoUpload = false;

          private boolean useFlash = false;

       

          public int getSize() {

              if (getFiles().size()>0){

                  return getFiles().size();

              }else

              {

                  return 0;

              }

          }

       

          public FileUploadBean() {

            uploadsAvailable = 999;

            clearUploadData();

          }

       

          public void clearUploadData() {

              files.clear();

              setUploadsAvailable(999);

          }

       

          public long getTimeStamp(){

              return System.currentTimeMillis();

          }

       

          public List<File> getFiles() {

              return files;

          }

       

          public void setFiles(ArrayList<File> files) {

              this.files = files;

          }

       

          public int getUploadsAvailable() {

              return uploadsAvailable;

          }

       

          public void setUploadsAvailable(int uploadsAvailable) {

              this.uploadsAvailable = uploadsAvailable;

          }

       

       

          public boolean isAutoUpload() {

              return autoUpload;

          }

       

          public void setAutoUpload(boolean autoUpload) {

              this.autoUpload = autoUpload;

          }

       

          public boolean isUseFlash() {

              return useFlash;

          }

       

          public void setUseFlash(boolean useFlash) {

              this.useFlash = useFlash;

          }

       

      }

       

       

      FileUploadController

      public class FileUploadController extends PolicyPageController {

       

        private static final long serialVersionUID = 8330416751801485051L;

       

        public void launchUploadPanel() {

       

            FileUploadBean bean = (FileUploadBean) SessionUtil.get(BeanIdentifier.FILE_UPLOAD_BEAN);

            if (bean == null) {

                bean = new FileUploadBean();

            }

            SessionUtil.put(BeanIdentifier.FILE_UPLOAD_BEAN, bean);

       

        }

       

        public void listener(UploadEvent event) throws IOException{

              FileUploadBean bean = (FileUploadBean) SessionUtil.get(BeanIdentifier.FILE_UPLOAD_BEAN);

              UploadItem item = event.getUploadItem();

              File file = new File();

              file.setLength(item.getData().length);

              file.setName(item.getFileName());

              file.setData(item.getData());

              bean.getFiles().add(file);

              bean.setUploadsAvailable(bean.getUploadsAvailable()-1);

              SessionUtil.put(BeanIdentifier.FILE_UPLOAD_BEAN, bean);

          }

       

      }

       

       

      web.xml

      <filter>

          <display-name>RichFaces Filter</display-name>

          <filter-name>richfaces</filter-name>

          <filter-class>org.ajax4jsf.Filter</filter-class>

          <init-param>

              <param-name>createTempFiles</param-name>

              <param-value>false</param-value>

          </init-param>

          <init-param>

              <param-name>maxRequestSize</param-name>

              <param-value>1000000</param-value>

          </init-param>

      </filter>

       

       

      fileUploadPanel.xhtml (this is included in an xhtml file with <h:form> tag)

       

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"

          xmlns:ui="http://java.sun.com/jsf/facelets"

          xmlns:h="http://java.sun.com/jsf/html"

          xmlns:f="http://java.sun.com/jsf/core"

          xmlns:a4j="http://richfaces.org/a4j"

          xmlns:rich="http://richfaces.org/rich">

       

                <rich:modalPanel id="fileUploadPanel" resizeable="false" autosized="true" headerClass="columnHeaderBG">

                    <f:facet name="header">

                                    <h:outputText value="#{label.label74}" />

                          </f:facet>

       

                    <h:panelGrid column="1">

       

                    <a4j:outputPanel>

       

                        <h:panelGrid columns="2">

       

                            <rich:fileUpload fileUploadListener="#{FileUploadController.listener}"

                                id="upload"

                                maxFilesQuantity="#{FileUploadBean.uploadsAvailable}" >

                                <a4j:support event="onuploadcomplete" reRender="info" />

                            </rich:fileUpload>

       

                                  <rich:panel id="info" style="height: 249px; width:300px;">

       

                          <h:outputText value="No files currently uploaded"

                              rendered="#{FileUploadBean.size eq 0}" />

       

                                                        <rich:dataTable id="uploadedFilesList"

                                                                            value="#{FileUploadBean.files}"

                                                                            var="file">                  

                                    <rich:column>

                                                                            <h:outputText value="#{file.name}" />

                                                                  </rich:column>

                                                                  <rich:column>

                                                                            <h:outputText value="#{file.length}" />

                                                                  </rich:column>

                          </rich:dataTable>

                          <rich:datascroller align="center" for="uploadedFilesList"

                                                                  page="1" reRender="sc1" id="sc1" rendered="#{FileUploadBean.size ge 1}"/>

       

                      </rich:panel>

                        </h:panelGrid>

       

       

                        <center>

                                  <a4j:commandButton id="btnClose"

                                                        styleClass="InputButtonRate"

                                                        value="#{label.actionclose}" 

                                                        oncomplete="Richfaces.hideModalPanel('fileUploadPanel')">

                                              </a4j:commandButton>

                        </center>

       

                    </a4j:outputPanel>

       

                    </h:panelGrid>

       

          </rich:modalPanel>

      </ui:composition>

       

       

      The problem is after clicking the UPLOAD button, the method in the fileUploadListener attribute is not being called.uploadPanel.PNG

      There are no errors in the console that is why I am having a hard time tracing what may be the cause of the problem. If you need some more information on my part, I'd be more than willing to provide. Your help will be much appreciated.

       

      Thanks!
      Eric