0 Replies Latest reply on Aug 28, 2009 7:53 AM by damian.sinczak

    Rich:fileUpload fileUploadListener never called.

    damian.sinczak

      I've notice that this topis has been started few times and I read every post that was about fileUploadListener in fileUpload control and still I can't get it work properly. listner is never called by fileUpload. Because of that few components are never rerendered because they depend on files uploaded by control. This is my configuration and source code.

      This is page that contains uploadFile control (a lot of trash but I will refactor after I get this work):

      <div class="contentDiv" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
       xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j"><f:subview
       id="policyManagementContent">
      
       <h:form id="pageForm">
       <rich:dataTable id="policiesTable" rows="10" align="center" onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
       onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'" cellpadding="0" cellspacing="0"
       width="650" border="0" var="policy" value="#{policiesBean.policiesList}">
      
       <f:facet name="header">
       <rich:columnGroup>
       <rich:column colspan="5">
       <h:outputText value="Policy information" />
       </rich:column>
       <rich:column rowspan="2">
       <h:outputText value="Actions" />
       </rich:column>
       <rich:column sortBy="#{policy.id}" breakBefore="true" sortable="true" sortExpression="#{policy.id}">
       <h:outputText value="Id" />
       </rich:column>
       <rich:column sortBy="#{policy.name}" sortable="true" sortExpression="#{policy.name}">
       <h:outputText value="Name" />
       </rich:column>
       <rich:column sortBy="#{policy.version}" sortable="true" sortExpression="#{policy.version}">
       <h:outputText value="Version" />
       </rich:column>
       <rich:column sortBy="#{policy.isActive}" sortable="true" sortExpression="#{policy.isActive}">
       <h:outputText value="Is active" />
       </rich:column>
       <rich:column sortBy="#{policy.addingDate}" sortable="true" sortExpression="#{policy.addingDate}">
       <h:outputText value="Add date" />
       </rich:column>
       </rich:columnGroup>
       </f:facet>
      
       <rich:column sortBy="#{policy.id}" sortable="true" sortExpression="#{policy.id}">
       <h:outputText value="#{policy.id}">
       </h:outputText>
       </rich:column>
       <rich:column sortBy="#{policy.name}" sortable="true" sortExpression="#{policy.name}">
       <h:outputText value="#{policy.name}">
       </h:outputText>
       </rich:column>
       <rich:column sortBy="#{policy.version}" sortable="true" sortExpression="#{policy.version}">
       <h:outputText value="#{policy.version}">
       </h:outputText>
       </rich:column>
       <rich:column sortBy="#{policy.isActive}" sortable="true" sortExpression="#{policy.isActive}">
       <h:selectBooleanCheckbox value="#{policy.isActive}" readonly="true" disabled="true">
       </h:selectBooleanCheckbox>
       </rich:column>
       <rich:column sortBy="#{policy.addingDate}" sortable="true" sortExpression="#{policy.addingDate}">
       <h:outputText value="#{policy.addingDate}">
       <f:convertDateTime pattern="dd.MM.yyyy HH:mm" />
       </h:outputText>
       </rich:column>
       <rich:column>
       <h:commandButton value="Toggle active" action="#{policiesBean.togglePolicyActive}">
       <f:setPropertyActionListener target="#{policiesBean.togglePolicyActiveId}" value="#{policy.id}" />
       </h:commandButton>
       </rich:column>
       </rich:dataTable>
       <rich:datascroller align="center" for="policiesTable" maxPages="18" id="sc1" />
      
      
       <rich:spacer height="30" />
      
       <rich:panel id="controlsPanel" style="margin-right:auto;margin-left:auto;width:650px;"
       bodyClass="rich-laguna-panel-no-header">
       <h:panelGrid border="0" columns="2">
       <h:form>
       <h:commandButton value="Reload policies" id="reloadPolicies" action="#{policiesBean.refreshPolicies}">
       </h:commandButton>
       </h:form>
       </h:panelGrid>
       </rich:panel>
      
       <rich:spacer height="30" />
       </h:form>
      
       <rich:panel id="uploadPolicyPanel" style="margin-right:auto;margin-left:auto;width:650px;" header="Upload policy">
       <rich:panel bodyClass="rich-laguna-panel-no-header" style="margin-right:auto;margin-left:auto;width:600px;">
       <rich:fileUpload fileUploadListener="#{policiesBean.listener}" maxFilesQuantity="1" id="upload"
       immediateUpload="false" acceptedTypes="class, jar" allowFlash="true" listHeight="60" listWidth="577"
       sizeErrorLabel="Too big file size. Check upload settings."
       transferErrorLabel="Error during file upload. Clear and try again." style="align:center;width:420px;">
       <f:facet name="label">
       <h:outputText value="{_KB}KB from {KB}KB uploaded --- {mm}:{ss}" />
       </f:facet>
       <a4j:support event="onuploadcomplete" reRender="uploadInfo" />
       </rich:fileUpload>
       </rich:panel>
       <rich:spacer height="2" />
       <h:panelGroup id="uploadInfo" rendered="#{policiesBean.uploadedData != null}">
       <rich:panel bodyClass="rich-laguna-panel-no-header" style="margin-right:auto;margin-left:auto;width:600px;">
       HEJ HEJ
       </rich:panel>
       <rich:spacer height="2" />
       <rich:panel bodyClass="rich-laguna-panel-no-header" style="margin-right:auto;margin-left:auto;width:600px;">
       <h:panelGrid border="0" columns="2">
       <a4j:commandButton value="Reset upload" id="resetPanel" rendered="#{policiesBean.uploadedData != null}"
       action="#{policiesBean.resetUpload}" reRender="uploadPolicyPanel">
       </a4j:commandButton>
       </h:panelGrid>
       </rich:panel>
       </h:panelGroup>
       </rich:panel>
      </f:subview></div>
      


      I've tried putting it inside and outside form, panel, paneGroup; changing type of form from h:form to a4j form and many other sometimes even not logic possibilites and nothing worked.

      Backing bean source code (Session scope):
      public class PoliciesBean {
      
       @EJB(mappedName = "PolicyManager")
       private PolicyManager policyManager;
      
       private List<PolicyDTO> policiesList = null;
      
       private byte[] uploadedData = null;
      
       private List<UploadItem> uploadData;
      
       public PoliciesBean() {
      
       }
      
       public void togglePolicyActive(){
       this.policyManager.togglePolicyActive(this.togglePolicyActiveId);
       }
      
       public List<PolicyDTO> getPoliciesList() {
       if (null == this.policiesList) {
       try {
       this.policiesList = this.policyManager.retrieveAllPolicies();
       } catch (Exception e) {
       e.printStackTrace();
       }
       }
       return policiesList;
       }
      
       public void refreshPolicies(){
       this.policiesList = null;
       }
      
       public void listener(UploadEvent event) throws Exception {
       UploadItem item = event.getUploadItem();
       this.uploadedData = item.getData();
       }
      
       public void resetUpload(){
       this.uploadedData = null;
       }
      
       /* GETTERS AND SETTERS */
      
       public void setPoliciesList(List<PolicyDTO> policiesList) {
       this.policiesList = policiesList;
       }
      
       public byte[] getUploadedData() {
       return uploadedData;
       }
      
       public void setUploadedData(byte[] uploadedData) {
       this.uploadedData = uploadedData;
       }
      
       public List<UploadItem> getUploadData() {
       return uploadData;
       }
      
       public void setUploadData(List<UploadItem> uploadData) {
       this.uploadData = uploadData;
       }
      }
      


      And my faces xml configuration part:
       <managed-bean>
       <managed-bean-name>policiesBean</managed-bean-name>
       <managed-bean-class>com.comarch.nltbm.jsf.beans.PoliciesBean</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
       </managed-bean>
      


      And configaration part od web.xml
      <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>server</param-value>
       </context-param>
       <context-param>
       <description>
       This parameter enables partial state saving.
       </description>
       <param-name>javax.faces.PARTIAL_STATE_SAVING_METHOD</param-name>
       <param-value>false</param-value>
       </context-param>
       <context-param>
       <param-name>org.richfaces.SKIN</param-name>
       <param-value>blueSky</param-value>
       </context-param>
       <context-param>
       <param-name>org.richfaces.CONTROL_SKINNING</param-name>
       <param-value>enable</param-value>
       </context-param>
       <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>5000000</param-value>
       </init-param>
       </filter>
       <filter-mapping>
       <filter-name>richfaces</filter-name>
       <servlet-name>Faces Servlet</servlet-name>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>FORWARD</dispatcher>
       <dispatcher>INCLUDE</dispatcher>
       </filter-mapping>