Just sharing a code snippet about how to implement a jQuery+Bootstrap progress bar for a background operation in Tapestry 5. There’s not a lot to it, but it took me a while and serious digging through the internet to find how to make it work. Essentially it’s based on a coupleĀ of examples and references I found:
- http://permalink.gmane.org/gmane.comp.java.tapestry.user/85776
- https://github.com/uklance/tapestry-stitch
But IĀ simplified things because I don’t like the over-design Java can easily make you do…
Basically, it’s a server side (ProgressBar.java) and client side (progressbar.js) component that communicate with each other via ajax.
All you have to do is set it up in the template, and implement a function to return the progress (double onUpdateFromProgressBar()
).
To run a process in the background I used the ParallelExecutor which uses the Invokable> interface. So to add the progress tracking to Invokable I extended it like in the example from Lance (here).
Then it’s all very simple just tracking the progress within the background process and the client is polling it periodically.
Here’s the gist:
Enjoy!
Roy