Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Closes #983 -- correct ordering for functions created in JsToAppend. …

…Closes #955 -- better handling of S.redirectTo including working in Ajax
  • Loading branch information...
commit 29395c5486fe1536e68450076f49b2121e957889 1 parent d7daee7
@dpp dpp authored
View
8 web/webkit/src/main/scala/net/liftweb/http/LiftServlet.scala
@@ -422,7 +422,13 @@ class LiftServlet extends Loggable {
case _ =>
try {
- val what = flatten(liftSession.runParams(requestState))
+ val what = flatten(try {
+ liftSession.runParams(requestState)
+ } catch {
+ case ResponseShortcutException(_, Full(to), _) =>
+ import js.JsCmds._
+ List(RedirectTo(to))
+ })
val what2 = what.flatMap {
case js: JsCmd => List(js)
View
6 web/webkit/src/main/scala/net/liftweb/http/LiftSession.scala
@@ -985,14 +985,14 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
// Phase 1: snippets & templates processing
val rawXml: NodeSeq = processSurroundAndInclude(PageName get, xhtml)
+ // Phase 2: Head & Tail merge, add additional elements to body & head
+ val xml = merge(rawXml, request)
+
// Make sure that functions have the right owner. It is important for this to
// happen before the merge phase so that in merge to have a correct view of
// mapped functions and their owners.
updateFunctionMap(S.functionMap, RenderVersion get, millis)
- // Phase 2: Head & Tail merge, add additional elements to body & head
- val xml = merge(rawXml, request)
-
notices = Nil
// Phase 3: Response conversion including fixHtml
LiftRules.convertResponse((xml, overrideResponseCode.is openOr code),
View
12 web/webkit/src/main/scala/net/liftweb/http/ResponseShortcutException.scala
@@ -39,10 +39,11 @@ object ContinueResponseException {
}
-class ResponseShortcutException(_response: => LiftResponse, val doNotices: Boolean) extends LiftFlowOfControlException("Shortcut") {
- lazy val response = _response
+final case class ResponseShortcutException(_response: () => LiftResponse, redirectTo: Box[String], doNotices: Boolean) extends LiftFlowOfControlException("Shortcut") {
+ lazy val response = _response()
- def this(resp: => LiftResponse) = this (resp, false)
+ def this(resp: => LiftResponse, doNot: Boolean) = this(() => resp, Empty, doNot)
+ def this(resp: => LiftResponse) = this (() => resp, Empty, false)
}
object ResponseShortcutException {
@@ -50,7 +51,7 @@ object ResponseShortcutException {
new ResponseShortcutException(responseIt, true)
def redirect(to: String): ResponseShortcutException =
- new ResponseShortcutException(RedirectResponse(to, S responseCookies: _*), true)
+ new ResponseShortcutException(() => RedirectResponse(to, S responseCookies: _*), Full(to), true)
def redirect(to: String, func: () => Unit): ResponseShortcutException =
S.session match {
@@ -59,13 +60,12 @@ object ResponseShortcutException {
}
def seeOther(to: String): ResponseShortcutException =
- new ResponseShortcutException(SeeOtherResponse(to, S responseCookies: _*), true)
+ new ResponseShortcutException(() => SeeOtherResponse(to, S responseCookies: _*), Full(to), true)
def seeOther(to: String, func: () => Unit): ResponseShortcutException =
S.session match {
case Full(liftSession) => seeOther(liftSession.attachRedirectFunc(to, Full(func)))
case _ => seeOther(to)
}
-
}
View
4 web/webkit/src/main/scala/net/liftweb/http/S.scala
@@ -1084,7 +1084,7 @@ for {
* @see ResponseShortcutException
* @see # redirectTo ( String, ( ) => Unit)
*/
- def redirectTo[T](where: String): T = throw ResponseShortcutException.redirect(where)
+ def redirectTo(where: String): Nothing = throw ResponseShortcutException.redirect(where)
/**
* Redirects the browser to a given URL and registers a function that will be executed when the browser
@@ -1097,7 +1097,7 @@ for {
*
* @see # redirectTo ( String )
*/
- def redirectTo[T](where: String, func: () => Unit): T =
+ def redirectTo(where: String, func: () => Unit): Nothing =
throw ResponseShortcutException.redirect(where, func)
Please sign in to comment.
Something went wrong with that request. Please try again.