Alexander Chepurnoy

The Web of Mind

Valid Scala vs. Valid HTML : Play Views vs. Lift Views

| Comments

Play2 and Lift are major web frameworks in the Scala industry. And they are different. Let me describe view layer (V in the MVC) design principles of these frameworks. Note: the article covers only default and most popular approaches in both frameworks, but there many possibilities to go other way.

Play2 views are rendered with a Scala-based template engine that provides type and compiled checked templates. So a Play2 view is valid Scala code that could be checked during compilation:

@(news: List[NewsElement], events:List[FxEvent])
@import models._

@tilesOut(content: List[models.ContentElement]) = {
    <div id="home-tiles" class="container-fluid metro">
    @for((contentElem, index) <- content.zipWithIndex) {
            <div class="row-fluid">
        <div class="span3">
        @if(index%columnsInRow==columnsInRow-1 || index==content.size-1){




(real example from a metro-style site)

On other hand, a Lift view developed with “view-first” approach is valid HTML code like this:

<div lift="comet?type=Clock">
    <span id="time"></span>

(taken from Lift tutorial)

With controller code like:

object Tick
class Clock extends CometActor {
    Schedule.schedule(this, Tick, 10 seconds)

    def render = "#time *" #> now.toString

    override def lowPriority = {
        case Tick => 
            val js = SetHtml("time", Text(now.toString))
            Schedule.schedule(this, Tick, 10 seconds) 

Lift has MVC support also, but “view-first” is the main principle supported by the Lift community.

Valid Scala vs valid HTML? For me, Play2 way is more natural, Lift could be better only in some cases(however, it’s more friendly for a HTML guy in your team)

P.S. Nice Stackoverflow conversation Should I use Play or Lift for doing web development in Scala?