Saturday, 17 September 2011

Exploring the Skeleton Application


In Starting the Project, I discovered that the skeleton application provided by the basic maven archetype "magically" gave me a working application.  So...what's lurking in here?

When I get down to it, the first thing I'll want to do is write some tests.  First, though, let me see what I can figure out.  The page has some text "Welcome to your project!".  Where is that?

src/main/webapp/index.html



<div class="lift:surround?with=default;at=content">
  <h2>Welcome to your project!</h2>
  <p>
    <div class="lift:helloWorld.howdy">
      Welcome to contactdb at <span id="time">The current time</span>
    </div>
  </p>
</div>


So this is Lift at work.  I'm no UI or Web developer, but this is clearly HTML using div tags (rather than tables) to control layout.  Both of these specify a class.

The first specifies lift:surround which ultimately is going to reference the content of main/webapp/templates-hidden/default.html .  More on that file later, but for now it should be sufficient to accept that this is a way to give a common look-and-feel to all pages within the application (including the menu).

The second references lift:helloWorld.howdy which is talking about the class (and method) specified at ./main/scala/org/philgra/snippet/HelloWorld.scala :


package org.philgra {
package snippet {


import _root_.scala.xml.{NodeSeq, Text}
import _root_.net.liftweb.util._
import _root_.net.liftweb.common._
import _root_.java.util.Date
import org.philgra.lib._
import Helpers._


class HelloWorld {
  lazy val date: Box[Date] = DependencyFactory.inject[Date] // inject the date


  // bind the date into the element with id "time"
  def howdy = "#time *" #> date.map(_.toString)


}
}
}


I'm a bit surprised to find so many imports, particularly boiler-plate looking things.  Without (yet) getting into the nuances of Scala we can sort of see how the HTML <span id="time"> links into the method howdy and a binding.  I have to be honest, this doesn't make a huge amount of sense to me at this point: it seems that the developer of this is trying to be too clever by half.  That or Lift is goofy :)

So, that's about a wrap for now...I'll next look into the tests.  There's also User and DependencyFactory classes, but at least we have the jist of how the HTML is being built.

No comments:

Post a Comment