Up: Chapter 4


Much of what we do to build web applications is generating screens that associate input with dynamic content. Lift provides Screen and Wizard for building single page and multi-page input forms with validation, back-button support, etc.
So, let’s look at the HTML for a screen:
<div id="main" class="lift:surround?with=default&at=content">
    Let's use Lift's LiftScreen to build complex
    simple screen input forms.
  <div class="lift:ScreenExample">
    Put your form here
We don’t explicitly declare the form elements. We just point to the snippet which looks like:
package code
package snippet
import net.liftweb._
import http._
 * Declare the fields on the screen
object ScreenExample extends LiftScreen {
  // here are the fields and default values
  val name = field("Name", "")
  // the age has validation rules
  val age = field("Age", 0, minVal(13, "Too Young"))
  def finish() {
    S.notice("Name: "+name)
    S.notice("Age: "+age)
In the screen, we define the fields and their validation rules and then what to do when the screen is finished. Lift takes care of the rest.
The markup for generating the form, by default, is found in /templates-hidden/wizard-all.html. You can also select templates on a screen-by-screen basis.
Up: Chapter 4

(C) 2012 David Pollak