{ S.notice(\"Hello world!\") S.redirectTo(\"/index\")" />
开发者

Why doesn't S.notice show up after redirect in lift mvc v2.3

开发者 https://www.devze.com 2023-03-09 21:03 出处:网络
when requesting: case \"page\" :: AsInt(id) :: Nil => { S.notice(\"Hello world!\") S.redirectTo(\"/index\")

when requesting:

case "page" :: AsInt(id) :: Nil => { S.notice("Hello world!") S.redirectTo("/index") }

redirects to:

case "index" :: Nil => { // replace the contents of the element with id "time" with the date "#time *" #> DependencyFactory.inject[Date].map(_.toString) }

however "Hello world!" doesn't show up. It will show up on page if I comment th开发者_如何学运维e redirectTo.

Can anyone tell me why the session isn't persisting past the redirect?


I suppose that's because S.notice() places message in request scope and it's not available after redirect (new request is created).

See following quotes from Exploring Lift book:

The net.liftweb.http.S object represents the state of the current request.

The messages that you send are held by a RequestVar in the S object.

But:

You can also send Lift messages (notices, warnings, and errors) that will be rendered in the redirected page, as well as cookies to be set on redirect. Similarly, there is an overloaded version of S.redirectTo that allows you to specify a function to be executed when the redirect is processed.

So I think you can use following version of redirectTo method for this purpose:

def redirectTo [T] (where: String, func: () ⇒ Unit) : T

and make S.notice call inside registered function (second parameter).

Best Regards, Vladimir


try this...

S.redirectTo("/index", () => S.notice("Hello World!"))
0

精彩评论

暂无评论...
验证码 换一张
取 消