DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. First Bit of Lift 3.0

First Bit of Lift 3.0

David Pollak user avatar by
David Pollak
·
Feb. 22, 13 · Interview
Like (0)
Save
Tweet
Share
4.49K Views

Join the DZone community and get the full member experience.

Join For Free

Lift is growing

Lift is growing and evolving.

I've just started the Lift 3.0 code branch. Lift 3.0 will be based on Scala 2.10+ and will use features exclusive to 2.10 including macros. Lift 3.0 will also cut away at a lot of cruft that's grown onto Lift over the years, so 3.0 will have a bunch of breaking changes.

The Future is Futures

Lift 3.0 will support Futures (specifically LAFutures which are Lift's time-tested, solid Futures) such that you can do stuff like this in a REST call:

object DelayedRest extends RestHelper {
  serve {
    case "delay" :: Nil Get _ =>
    LAFuture(() => {
      Thread.sleep(2000)
      <b>Hello</b>})
  }
}

When Lift detects that an LAFuture is servicing being returned from the REST call, Lift will automatically use the Container's asynchronous support, suspect the request thread, and only restart the request thread when the answer is available.

There will be other places in the code where Lift automatically works with Futures.

Any data- attribute can be processed in Lift

Lift's Designer Friendly Templates have been totally awesome. And with 3.0, the awesomeness is extended.

Lift's Data Attribute Processing allows you to hook into Lift's templating and process any data attribute, like so:

    LiftRules.dataAttributeProcessor.append {
      case ("wombat", str, nodes) => ("div *+" #> str).apply(nodes)
    }

Which will transform:

<div data-wombat="David">My wombat is named: </div>

Into:

<div>My wombat is named: David</div>

Data Attribute Processors also deal well with Futures, so:

    LiftRules.dataAttributeProcessor.append {
      case ("ad-network", service, _) => LAFuture(() => getAdsFor(service))
    }

Will not block the main rendering thread, but will be computed off-thread and the result will be integrated onto the page when the result becomes available.

There are a ton of uses for Data Attribute Processing for creating project specific templating for HTML folks to do lots of stuff server-side.

Acting across Address Spaces

Actors are cool. They are a nice asynchronous mechanism for processing data.

Wouldn't it be nice if you had client-side actors (a JavaScript function? that when called would serialize the object as JSON and send it to an Actor on the server)?

Wouldn't it be cool if there was a server-side proxy of a function on the client such that when you send JSON-serializable data to the server-object, it gets JSON serialized and sent to the client?

Well, Lift 3.0 bridges address spaces for object between the browser and the server. Yep, that's right, Lift 3.0 is the first web framework to support distributed objects across browser and server.

Here's how it's done:

      // get a server-side actor that when we send
      // a JSON serializable object, it will send it to the client
      // and call the named function with the parameter
      val clientProxy = sess.serverActorForClient("changeNode")

      // Create a server-side Actor that will receive messaes when
      // a function on the client is called
      val serverActor = new ScopedLiftActor {
        override def lowPriority = {
          case JString(str) => clientProxy ! ("You said: "+str)
        }
      }
      
      Script(JsRaw("var sendToServer = "+sess.clientActorFor(serverActor).toJsCmd).cmd &
        JsRaw("function changeNode(str) {document.getElementById(\"foo\").innerHTML = str;}").cmd)

So, yes, it's that simple. clientProxy ! "Hi" will serialize the String and invoke the changeNode function on the client with the string.

Call sendToServer from JavaScript on the client and voila, the Actor on the server-side gets a message.

So, on the client, we say:

<button onclick="sendToServer(document.getElementById('in').value)">Click me</button>

And we get a server-round-trip.

The code

You can see sample code on GitHub.

Thanks!

Lift (web framework)

Published at DZone with permission of David Pollak. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Get Page Source in Selenium Using Python
  • How To Use Terraform to Provision an AWS EC2 Instance
  • Top 12 Technical Skills Every Software Tester Must Have
  • Continuous Development: Building the Thing Right, to Build the Right Thing

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: