rich:fileUpload and rich:progressBar
canbay Aug 24, 2011 3:41 AMHi,
I am using Richfaces 4.0.0.Final under Tomcat 7.0.
Here is the xhtml-part
<rich:fileUpload fileUploadListener="#{fileUploadBean.listener}" id="upload" acceptedTypes="csv, zip" maxFilesQuantity="1"> <a4j:ajax event="uploadcomplete" execute="@none" render="info" /> <a4j:ajax event="filesubmit" execute="@form" render="info" /> <f:facet name="progress"> <rich:progressBar interval="500" id="pb" value="#{fileUploadBean.currentValue}" label="#{fileUploadBean.processed} of #{fileUploadBean.toProcess} processed."> </rich:progressBar> </f:facet> </rich:fileUpload>
and here the fileUploadBean
import java.io.Serializable; import javax.inject.Inject; import javax.inject.Named; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.richfaces.event.FileUploadEvent; import org.richfaces.model.UploadedFile; import org.springframework.context.annotation.Scope; import de.mbb.abgst.service.Loader; @Named("fileUploadBean") @Scope(value = "session") public class FileUploadBean implements Serializable { private final static Log log = LogFactory.getLog(FileUploadBean.class); private static final long serialVersionUID = -4473074092916884407L; @Inject private Loader loader; private int lineCount = 0; public FileUploadBean() { } public void listener(FileUploadEvent event) throws Exception { UploadedFile item = event.getUploadedFile(); lineCount = loader.countLine(item.getInputStream()); log.info("Start loading ..."); loader.load(item.getInputStream()); } public int getProcessed() { log.info("getProcessed"); int processed = loader.getProcessed(); log.info("processed: " + processed); return processed; } public int getToProcess() { log.info("getToProcessed"); return lineCount; } public int getCurrentValue() { int ret = 0; if (lineCount > 0) { ret = getProcessed()*100/lineCount; } return ret; } }
Most of the time is spend on
loader.load(item.getInputStream())
Uploading takes just a couple of seconds, but the progressbar is filled after
uploading is processed.
I thought, I could overwrite the progressbar with own configuration, but the shown code has no effect.
Trying to put a separate progressbar would be also fine, but
<a4j:ajax event="filesubmit" execute="@form" render="info" />
is not firing (although an explicit onfilesubmit is firing) so that I can't enable the separate progressbar.
Any idea or best practice ?
Thanks and regards
Özkan