After searching through SO, and not finding anything useful, I decided to post this question.
Is it possible to execute the "Redirect after Post" idiom in Lift - and if so how?
Yes it is possible.
One thing to notice, is that in order to avoid "form resubmission" warning, we need to redirect to ourselves when we want to show things like errors or notices, as per the mail archive discussion by Naftoli Gugenheim:
If you are using a StatefulSnippet call redirectTo(S.uri) on in to load the
same page with the same snippet instance.
So, for example when processing a form we can do something like this:
def process() = {
if (patientName== "Joe") {
S.error("Joe not allowed!")
}
val dateRegex="\\d\\d/\\d\\d/\\d\\d\\d\\d";
if (!birthdate.matches(dateRegex)) {
S.error("birthdate", "Invalid date. Please enter date in the form dd/mm/yyyy.")
}
S.errors match {
//Redirect on success
case Nil =>S.notice("Patient name: " + patientName); S.redirectTo("/")
//Redirect to ourselves - and show errors
case _ =>S.redirectTo(S.uri)
}
}