Reputation: 3009
I am trying to implement some flow control in Play 2.0.3, kind of a wizard with several steps. What is the best way to do it in Play?
I want to have multi-step flows, like step1 -> step2 -> finish
The main problem is not to allow user to skip for example step2 and go straight to finish (user can manually input a link in the browser /finish ).
Thanks. Please let me know if I haven't explained myself well.
Upvotes: 2
Views: 1069
Reputation: 5951
I would store the steps in the database (for long term) or in the cache (on short term). This way you can build some logic if (secondQuestionAnswered) { .. }
and be sure that your user did not skipped anything and / or the user can finish the steps when he wants to. And persisting in DB or cache would also benefit if your app grow and you need to scale it.
Upvotes: 1
Reputation: 9663
A completely stateless way could consist in storing all data in the URLs of steps, where the step n + 1
contains all data from step n
:
GET /step1 controllers.Application.step1
GET /step2 controllers.Application.step2(dataFromStep1)
GET /step3 controllers.Application.step3(dataFromStep1, dataFromStep2)
POST /finish controllers.Application.finish
The advantages of this solution are its simplicity and the fact that checking that all required steps have been completed before the next step is performed for free by the Play! router.
However, if you have a lot of data your URLs will be huge, making this solution less applicable. In such a case, you need to:
/step2
URL won’t return the same thing for different users ;Upvotes: 2
Reputation: 55798
You have at least two options:
Upvotes: 4