Permalink
Browse files

Add LiftRules noCometSessionCmd/noAjaxSessionCmd.

These are the JsCmds that will be sent to the client when a session is
missing for a comet or ajax request, respectively. For comets, no comet
session is a state where a comet request comes in with no associated
session OR with a session that has no associated CometActors (typically
this happens on server reload).
  • Loading branch information...
Shadowfiend committed Jun 25, 2012
1 parent 1f00e15 commit b740ee8e6b3e524d56386a83c4fd66db9c15373c
@@ -599,10 +599,44 @@ class LiftRules() extends Factory with FormVendor with LazyLoggable {
@volatile var liftCoreResourceName = "i18n.lift-core"
/**
- * Where to send the user if there's no comet session
+ * Where to send the user if there's no comet session. Note that this is
+ * contingent on an unchanged LiftRules.noCometSessionCommand and on
+ * liftComet.lift_sessionLoss not being overridden client-side.
*/
+ @scala.deprecated("Use LiftRules.noCometSessionCmd.")
@volatile var noCometSessionPage = "/"
+ /**
+ * The JsCmd to execute when the comet session is lost. The comet
+ * session is considered lost when either (a) a comet request comes
+ * in for a session that does not exist on the server or (b) a comet
+ * request comes in for a session that has no associated comet actors
+ * (this typically happens when the server restarts).
+ *
+ * By default, we invoke liftComet.lift_sessionLoss, which can be
+ * overridden client-side for more complex work.
+ * liftComet.lift_sessionLoss redirects to
+ * LiftRules.noCometSessionPage by default for now, though
+ * noCometSessionPage is deprecated and will be replaced by a
+ * default of reloading the current page.
+ */
+ val noCometSessionCmd = new FactoryMaker[JsCmd](
+ () => JsCmds.Run("liftComet.lift_sessionLoss()")
+ ) {}
+
+ /**
+ * The JsCmd to execute when the ajax session is lost. The ajax
+ * session is considered lost when either an ajax request comes in for
+ * a session that does not exist on the server.
+ *
+ * By default, we invoke liftAjax.lift_sessionLoss, which can be
+ * overridden client-side for more complex work.
+ * liftAjax.lift_sessionLoss reloads the page by default.
+ */
+ val noAjaxSessionCmd = new FactoryMaker[JsCmd](
+ () => JsCmds.Run("liftAjax.lift_sessionLoss()")
+ ) {}
+
/**
* Put a function that will calculate the request timeout based on the
* incoming request.
@@ -220,7 +220,7 @@ class LiftServlet extends Loggable {
if (pathLen < 2) false
else {
val kindaComet = wp.head == LiftRules.cometPath
- val cometScript = (len >= 3 && kindaComet &&
+ val cometScript = (pathLen >= 3 && kindaComet &&
wp(2) == LiftRules.cometScriptName())
(kindaComet && !cometScript) && req.acceptsJavaScript_?
@@ -255,11 +255,11 @@ class LiftServlet extends Loggable {
} else {
val cmd =
if (isComet)
- js.JE.JsRaw("liftComet.sessionLoss(); lift_toWatch = {};").cmd
+ js.JE.JsRaw(LiftRules.noCometSessionCmd.vend.toJsCmd + ";lift_toWatch = {};").cmd
else
- js.JE.JsRaw("liftAjax.sessionLoss()").cmd
+ js.JE.JsRaw(LiftRules.noAjaxSessionCmd.vend.toJsCmd).cmd
- Full(new JsCommands(cmd).toResponse)
+ Full(new JsCommands(cmd :: Nil).toResponse)
}
}
// if the request is matched is defined in the stateless table, dispatch
@@ -563,7 +563,7 @@ class LiftServlet extends Loggable {
sessionActor.getAsyncComponent(name).toList.map(c => (c, toLong(when)))
}
- if (actors.isEmpty) Left(Full(new JsCommands(js.JE.JsRaw("liftComet.sessionLoss(); lift_toWatch = {};").cmd).toResponse))
+ if (actors.isEmpty) Left(Full(new JsCommands(LiftRules.noCometSessionCmd.vend :: js.JE.JsRaw("lift_toWatch = {};").cmd :: Nil).toResponse))
else requestState.request.suspendResumeSupport_? match {
case true => {
setupContinuation(requestState, sessionActor, actors)

0 comments on commit b740ee8

Please sign in to comment.