|
Lift Framework example source code file (LazyLoad.scala)
The Lift Framework LazyLoad.scala source code
/*
* Copyright 2007-2011 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.liftweb
package builtin
package snippet
import xml._
import http._
import common._
import actor._
import util._
import http.js._
import JsCmds._
import JE._
import S._
import Helpers._
/**
*
*/
object LazyLoad extends DispatchSnippet {
private object myFuncName extends TransientRequestVar(Helpers.nextFuncName)
private object myActor extends TransientRequestVar[Box[CometActor]](Empty)
def dispatch: DispatchIt = {
case _ => render _
}
def render(xhtml: NodeSeq): NodeSeq = {
(for {
session <- S.session ?~ ("FIXME: Invalid session")
} yield {
// if we haven't created the actor yet, register on this
// thread to create the AsyncRenderComet actor
if (myActor.isEmpty) {
LiftRules.cometCreationFactory.request.set(
(ccinfo: CometCreationInfo) =>
ccinfo match {
case CometCreationInfo(theType @ "AsyncRenderComet",
name,
defaultXml,
attributes,
session) => {
val ret = new AsyncRenderComet()
ret.initCometActor(session,
Full(theType),
name, defaultXml, attributes)
ret ! PerformSetupComet2(if (ret.sendInitialReq_?)
S.request.map(_.snapshot) else Empty)
// and save it in the request var
myActor.set(Full(ret))
Full(ret)
}
case _ => Empty
})
}
val id = Helpers.nextFuncName
val func: () => JsCmd =
session.buildDeferredFunction(() => Replace(id, xhtml))
<div id={id}>
{
S.attr("template") match {
case Full(template) => <lift:embed what={template}/>
case _ => <img src="/images/ajax-loader.gif" alt="Loading"/>
}
}
</div>++ (myActor.is match {
case Full(actor) => actor ! Ready(func); NodeSeq.Empty
case _ => session.setupComet("AsyncRenderComet", Full(myFuncName.is), Ready(func))
<tail>
Other Lift Framework examples (source code examples)Here is a short list of links related to this Lift Framework LazyLoad.scala source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.