HowTo use redirect with state
From Lift
LiftWeb allows you to use dispatch partial functions where you can define behavior based on URI sequences typically pattern matched. DispatchPf returns a ResponseIt which impersonates that response that needs to be provided to the client. Because you can return a ResponseIt you can return a RedirectResponse and consequentially a ResponseWithState. Through ResponseWithState you can specify a function to be executed on redirect and notices (errors, warnings and notices). Now in DispatchPf function you can utilize ResponseWithState like:
val dispatcher: LiftRules.DispatchPf = {
case RequestMatcher(r, ParsePath("showcities" :: _, _, _),_, _) => {case ignore => Can(RedirectWithState("/page2", RedirectState(myFunc _, "My error" -> Error)))}
}
or if you only want to pass a message
import MessageState._
val dispatcher: LiftRules.DispatchPf = {
case RequestMatcher(r, ParsePath("showcities" :: _, _, _),_, _) => {case ignore => Can(RedirectWithState("/page2", "My error" -> Error))}
}
or multiple messages ...
import MessageState._
val dispatcher: LiftRules.DispatchPf = {
case RequestMatcher(r, ParsePath("showcities" :: _, _, _),_, _) => {case ignore => Can(RedirectWithState("/page2",
MessageState("My error" -> Error, "something else" -> Error)))}
}
Br's,
Marius

