I am uploading a file in jsf and I would like to show user progress on the output label. This is what I have tried so far but its only getting updated after the upload is complete.
<h:form enctype="multipart/form-data" id="form_upload">
<p:panelGrid columns="2">
<p:outputLabel value="Total Excel count"/>
<h:outputLabel value="#{order.total_excel_count}"/>
<h:outputLabel value="Total Uploaded"/>
<h:outputLabel value="#{order.uploaded}"/>
<br/>
<br/>
<br/>
</p:panelGrid>
<p:messages closable="true" showDetail="true"/>
<p:fileUpload mode="simple" accept=".csv" value="#{order.uploadedFile}" />
<p:commandButton update="form_upload" value="Upload" action="#{order.upload}" ajax="false" id="uploader"/>
</h:form>
And my managed bean
@ManagedBean(name = "order")
@ViewScoped
public class Upload {
int uploaded,total_excel_count;//getter setter
private UploadedFile uploadedFile;//getter setter
public void upload() {
try {
InputStream in = uploadedFile.getInputstream();
Scanner scanner = new Scanner(in);
List<String> s = new ArrayList();
while (scanner.hasNext()) {
String line = scanner.nextLine();
s.add(line);
uploaded++;
doInsert(s);//method to do insert in the db
}
scanner.close();
total_excel_count=s.size();
setExist(total_excel_count-getUploaded());
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "!Some Error Occured", "Card Upload"));
e.printStackTrace();
}
}