Shwetanka
Shwetanka

Reputation: 5036

Lift - Snippet Failure Method not found

I've added this to my Boot.scala

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

Here is my Admin.scala in (admin/view package)

object Admin extends LiftView{

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

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

Here is my add_category template -

<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>

I'm trying to bind this with a snippet -Admin.scala in (admin/snippet package) with addCategory method.

 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"))
    )
  }

I'm getting this error -

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>

And in the logs -

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

Need help with this. I'm unable to figure out why lift is not able to find the method.

Upvotes: 2

Views: 1138

Answers (1)

jcern
jcern

Reputation: 7848

Have you added your admin package into LiftRules? Something like this should allow Lift to search admin.snippets for resolution:

LiftRules.addToPackages("admin")

Also, I believe you need to be calling the snippet as Admin.addCategory instead of with a :.

Edit:

I believe that the Lift HTML5 parser was case sensitive and had trouble with camel case method names. You may want to try renaming your method to all lowercase, or try calling your snippet as (instead of with the <lift: style):

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

   or

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

Upvotes: 2

Related Questions