提升 - 未找到Snippet Failure Method

时间:2013-01-24 11:35:26

标签: scala lift

我已将此添加到我的Boot.scala

LiftRules.viewDispatch.append({
  case List("admin", "categories") => Right(Admin)
})

这是我的Admin.scala(admin / view package)

object Admin extends LiftView{

  def dispatch = {
    case "add" => editCategory
  }

  def editCategory(): NodeSeq = {
    <lift:embed what="/admin/add_category"></lift:embed>
  }
}

这是我的add_category模板 -

<lift:surround with="admin" at="content">
  <div class="container-fluid" id="main_container">
    <lift:Admin:addCategory form="POST" class="form-horizontal">
      <fieldset>
        <legend>Add Category</legend>
        <div class="control-group">
          <label class="control-label" for="cat_name">Name</label>
          <div class="controls">
            <cat:name></cat:name>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label" for="cat_desc">Description</label>
          <div class="controls">
            <cat:desc></cat:desc>
            <cat:submit></cat:submit>
          </div>
        </div>
      </fieldset>
    </lift:Admin:addCategory>
  </div>
</lift:surround>

我正在尝试使用addCategory方法将其与(admin / snippet包)中的代码段-Admin.scala绑定。

 object name extends RequestVar("")
  object desc extends RequestVar("")

  def addCategory(in: NodeSeq): NodeSeq = {
    def doAdd() {
      //todo: Save Category
    }

    bind("cat", in,
      "name" -> SHtml.text(name.is, (n: String) => name(n), ("id", "cat_name"), ("class", "input-large")),
      "desc" -> SHtml.textarea(desc.is, (d: String) => desc(d), ("id", "cat_desc"), ("class", "input-large")),
      "submit" -> SHtml.submit("Save", doAdd, ("class", "btn btn-info"))
    )
  }

我收到此错误 -

Error processing snippet: admin:addcategory 
Reason: Method Not Found 
XML causing this error: 
 <lift:admin:addcategory class="form-horizontal" form="POST">
      <fieldset>
        <legend>Add Category</legend>
        <div class="control-group">
          <label for="cat_name" class="control-label">Name</label>
          <div class="controls">
            <cat:name></cat:name>
          </div>
        </div>
        <div class="control-group">
          <label for="cat_desc" class="control-label">Description</label>
          <div class="controls">
            <cat:desc></cat:desc>
            <cat:submit></cat:submit>
          </div>
        </div>
      </fieldset>
    </lift:admin:addcategory>

在日志中 -

[net.liftweb.http.LiftRules] - Snippet Failure: SnippetFailure(/admin/categories/add -> ParsePath(List(admin, categories, add),,true,false),Full(admin:addcategory),Method Not Found)

需要帮助。我无法弄清楚为什么电梯无法找到方法。

1 个答案:

答案 0 :(得分:2)

您是否已将admin包添加到LiftRules中?这样的事情应该允许Lift搜索admin.snippets以获得解决方案:

LiftRules.addToPackages("admin")

此外,我认为您需要将代码段调用Admin.addCategory而不是:

修改

我认为Lift HTML5解析器区分大小写,并且遇到驼峰式方法名称的问题。您可能希望尝试将方法重命名为全小写,或尝试将您的代码段调用为(而不是使用<lift:样式):

<div class="lift:admin.addCategory"> ... </div>

   or

<div data-lift="admin.addCategory"> ... </div>