ProgressBar <ajax call> inside rich:fileUpload is not working <richfaces 4.1.0>
yashyadav Mar 14, 2012 9:38 AMHi,
I am trying to use a Ajax based progressBar for the fileUpload to know the status.
but the progressBar never ticks further, the ajax calls never happens. it stays in intial value of zero.
I feel there is something wrong with my web.xml <any settings missing?> or reRender component has some issue...!.
Below is the screen-shot i get:
the browser stays in 0% forever.
I tried to debug the code and checked that method "getLoadedSwiftBlocks()" is called only in the begining <after clicking the upload button> and never called after that.
the code I have written:
upload.xhtml:
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<ui:composition >
<h:head>
<h:outputStylesheet name="css/default.css" />
<h:outputStylesheet name="css/cssLayout.css" />
<title>Facelet Title</title>
</h:head>
<h:body>
<style>
borderChk {
border: none;
}
</style>
<h:form>
<rich:fileUpload fileUploadListener="#{fnrUpload.parse}" id="upload"
acceptedTypes="sft,out,xls,xl,doc,docx,txt" noDuplicate="true" immediateUpload="true" allowFlash="true"
ontyperejected="alert('Only sft,out,xls,xl,doc,docx and txt files are accepted');" >
<f:facet name="progress" id="progressPanel">
<rich:progressBar mode="ajax" interval="900" enabled="true" id="pb"
value="#{swiftUpload.loadedSwiftBlocks}"
maxValue="#{swiftUpload.totalSwiftBlocks}" reRenderAfterComplete="progressPanel">
<h:outputText value="#{swiftUpload.loadedSwiftBlocks} % complete" />
</rich:progressBar>
</f:facet>
<a4j:ajax event="uploadcomplete" execute="@this" render="UploadCompletePane"
oncomplete="#{rich:component('UploadCompletePane')}.show()" />
</rich:fileUpload>
<rich:popupPanel id="UploadCompletePane" autosized="true" domElementAttachment="parent" header="Summary of uploaded file">
<h:panelGrid columns="1" border="0">
<rich:panel border="0">
<ui:repeat value="#{fnrUpload.parsedResult}" var="item">
<p><h:outputText value="#{item}"/></p>
</ui:repeat>
</rich:panel>
</h:panelGrid>
<h:panelGrid columns="2" border="0">
<rich:panel border="0">
<a4j:commandButton value="Confirm Saving" action="#{fnrUpload.saveUpload}" id="save"
render="upload" execute="UploadCompletePane"
oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('UploadCompletePane')}.hide();}" />
<a4j:commandButton value="Cancel" id="cancel"
onclick="#{rich:component('UploadCompletePane')}.hide(); return false;" />
</rich:panel>
</h:panelGrid>
</rich:popupPanel>
</h:form>
</h:body>
</ui:composition>
</html>
swiftUpload.java file:
@ManagedBean
@ViewScoped
public class SwiftUpload implements Serializable {
int totalSwiftBlocks=0;
int loadedSwiftBlocks=0;
public SwiftUpload() {
}
public int getTotalSwiftBlocks() {
return totalSwiftBlocks;
}
public void setTotalSwiftBlocks(int totalSwiftBlocks) {
this.totalSwiftBlocks = totalSwiftBlocks;
}
public int getLoadedSwiftBlocks() {
return loadedSwiftBlocks;
}
public void setLoadedSwiftBlocks(int loadedSwiftBlocks) {
this.loadedSwiftBlocks = loadedSwiftBlocks;
}
public List<String> upload(UploadedFile uploadedFile){
set totalSwiftBlocks to correctValue say 355
set loadedSwiftBlocks to 0
// Some processing of file
in for loop of elements of file {
// insert into dataBase
loadedSwiftBlocks++;
}
}
}
my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>FNR</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>org.ajax4jsf.SERIALIZE_SERVER_STATE</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>skin</param-name>
<param-value>blueSky</param-value>
</context-param>
<context-param>
<param-name>org.a4j.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<context-param>
<param-name>com.exadel.vcp.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/homePage.xhtml</welcome-file>
</welcome-file-list>
<mime-mapping>
<extension>ico</extension>
<mime-type>image/x-icon</mime-type>
</mime-mapping>
</web-app>
Can anyone please help me resolve the issue ?