Scala Liftweb : Re render page element without making any request to the server

Reading Time: 2 minutes

Lift introduces a powerful feature that enables developer to create rich interactive application using Comet and Ajax support . Using Comet , its easy to push content from server to browser by sending request asynchronously . AJAX works for a single client at a time , while Comet works for multiple users . Comet works like AJAX but in opposite direction .

In this blog , I am explaining how to re render a page element without making any request to server with no extra AJAX request , no page refreshes , nothing . As you can see in Gmail online Email portal , when an email is send by a user , receiver’s inbox is automatically gets updated and new email appears on receiver’s inbox .

Let’s take a look at a simple example . I am assuming that you are aware with basic Lift’s configuration . In this example , we are going to build a Notification snippet where client page is getting updated by server with current notification every 10 seconds .

In HTML file :

Now we are going to defined our comet actor by creating CometNotification class and extending CometActor :

Your Comet Actor !!

Current Time: Updates Messages 11 Feb, 2013 6:16:50 PM

Here time would be updated after every ten seconds .

Code base for the current example can be found on the Knoldus GitHub account here :

This is a simple example which will give the basic idea of Comet . You can build more complex application using Comet , such as chat application , Display notification like Facebook .

Written by 

Ayush is the Sr. Lead Consultant @ Knoldus Software LLP. In his 10 years of experience he has become a developer with proven experience in architecting and developing web applications. Ayush has a Masters in Computer Application from U.P. Technical University, Ayush is a strong-willed and self-motivated professional who takes deep care in adhering to quality norms within projects. He is capable of managing challenging projects with remarkable deadline sensitivity without compromising code quality.

Knoldus Pune Careers - Hiring Freshers

Get a head start on your career at Knoldus. Join us!