scala lift环境搭建(6)

当你需要将一个页面的内容分为几块时(大多数情况下你都会这样做).可以使用embed方式

将需要切分的页面内容放入embed.html,位置在webapp/下

在你需要调用这个内容地方使用

<span class="lift:embed?what=embed">
            replaced with embedded content
</span>

保存后刷新页面,你会看到此处内容被替换为embed.html中的内容(被引用的内容自然也会被解析)


一个增强型例子

/webapp/newtemp/form1.html

<div>
    <form class="lift:DumbForm?form=post">
        Name: <input name="name"/><br/>
        Age: <input name="age" value="0"/><br/>
        <input type="submit" value="Submit"/>
    </form>
</div>

index.html

<lift:embed what="/newtemp/form1">
        submit my first submit

    </lift:embed>

你还记得用create语句创建snippet么

lift create snippet
按提示输入DumbForm
package example.travel.snippet


import net.liftweb._
import http._
import util.Helpers._
import scala.xml.NodeSeq

object DumbForm {
  def render = {
    // define some variables to put our values into
    var name = ""
    var age = 0
    // process the form
    def process() {
      // if the age is < 13, display an error
      if (age < 13) S.error("Too young!")
      else {
        // otherwise give the user feedback and
        // redirect to the home page
        S.notice("Name: "+name)
        S.notice("Age: "+age)
        S.redirectTo("/")
      }
    }
    // associate each of the form elements
    // with a function... behavior to perform when the
    // for element is submitted
    "name=name" #> SHtml.onSubmit(name = _) & // set the name
      // set the age variable if we can convert to an Int
      "name=age" #> SHtml.onSubmit(s => asInt(s).foreach(age = _)) &
      // when the form is submitted, process the variable
      "type=submit" #> SHtml.onSubmitUnit(process)
  }
}

现在你可以重新运行一下程序,有什么惊喜发现么?


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值