I have a submit-button on the bottom of my JSF-page, which submits all the inputs (texts, files etc.) to the database and server. Due to the duration this action takes, I want to show the user the progress of the operation, and on finish redirect him on the finish-site.
My bean looks like:
<h:form enctype="multipart/form-data">
<p:commandButton widgetVar="submitButton" value="Save to DB" action="#{bean.submit}" onclick="PF('submitButton').disable();" />
<p:progressBar widgetVar="pbAjax" ajax="true" value="#{bean.saveProgress}" interval="1000" labelTemplate="{value}%" styleClass="animated" />
</h:form>
and my code:
private int saveProgress;
public String submit(){
for(int i = 0; i < 100; i++){ //dummy values
//DB operations
//file uploads
saveProgress = i;
System.out.println("Progress: " + saveProgress);
}
return "finished.xhtml";
}
//getter for saveProgress
the problem is, that neither the progressbar updates nor the pages navigates to finished.xhtml when done.
What am I doing wrong here? is this a thread-problem (because submit is not thread-safe?) How can I solve this problem?