フォームの処理 - lift

http://liftweb.net/index.php/Hello_Darwin#my_first_form

より写経する。

フォームを作る。

helloFrom.html
<lift:surround with="default" at="content">
    <h1>Hello Form</h1>
    Hello <lift:HelloForm.who />
    <br/>
    <form>
        <label for="whoField">Who :</label>
        <input type="text" name="whoField"/>
        <input type="submit" value="send"/>
    </form>
</lift:surround>


lift:surroundは、
http://liftweb.net/index.php/LiftTags
によると、withでテンプレート名を指定し、src/main/webapp/templates-hidden/default.htmlに
テンプレートが置かれているはずであり、実際置いてあった。
at属性でに展開することを指定しているのかと予想できる。

default.html
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lift="http://liftweb.net/">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<meta name="description" content="" />
		<meta name="keywords" content="" />
		
		<title>sandbox.lift.hellodarwin:hellodarwin:1.0-SNAPSHOT</title>
		<script id="jquery" src="/classpath/jquery.js" type="text/javascript"></script>
	</head>
	<body>
		<lift:bind name="content" />
		<lift:Menu.builder />
		<lift:msgs/>
	</body>
</html>

snipet作る。

入力された値をのところに展開して表示するプログラムのようだ。

HelloForm.scala
package sandbox.lift.hellodarwin.snippet

import net.liftweb.http.S

class HelloForm {
  def who = <tt>{S.param("whoField").openOr("")}</tt>
}

net.liftweb.http.Sは、

http://scala-tools.org/mvnsites/liftweb/lift-webkit/scaladocs/net/liftweb/http/S$object.html
より、
現在のリクエストとレスポンスを示すオブジェクトのようだ。

S.paramはCan[String]を返すことになっている。
クラスCanは
http://scala-tools.org/mvnsites/liftweb/lift-webkit/scaladocs/net/liftweb/util/Can.html
に説明があり、空かStringのどちらかであることを示すようだ。
openOr("")は値があればそれを返し、無ければ引数の値を返すCanのメンバである。