Can anyone teach me or direct to a working example to satisfy this requirement.
Scenario:
Here is a possible solution to this progress bar problem:
task.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
Progress Bar Example
TaskController.java
@Controller
@RequestMapping(value = "/task")
public class TaskController {
private Task task;
@RequestMapping("")
protected ModelAndView page() {
ModelAndView model = new ModelAndView(VIEW_DIR + "task");
if (this.task == null) {
this.task = new Task();
}
model.addObject("task", this.task);
return model;
}
@RequestMapping(value = "/status", method = GET)
public @ResponseBody
String getStatus() {
return task.getStatus();
}
@RequestMapping(value = "/progress", method = GET)
public @ResponseBody
int getProgress() {
return task.getProgress();
}
public ModelAndView form(@ModelAttribute Task task) {
this.task = task;
ModelAndView model = new ModelAndView(VIEW_DIR + "task");
task.execute();
model.addObject("task", this.task);
return model;
}
}
Task.java
public class Task {
private int total;
private int progress;
private String status;
public Task() {
this.status = "created";
// TODO get total here or pass via form
}
public void execute() {
status = "executing";
int i = 0;
while (i < total && status.equals("executing")) {
progress = (100 * (i + 1) / total);
i++;
}
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public int getProgress() {
return progress;
}
public void setProgress(int progress) {
this.progress = progress;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}