When you go to edit, are you passing the Category to be edited into the
categoryVar RequestVar? For instance, in your listing code say you had
something like:
def list (xhtml : NodeSeq) : NodeSeq = {
Model.createQuery[Category]("from Category").findAll.flatMap({category =>
<tr>
<td>{category.name}</td>
<td>{Shtml.link("/admin/categories/add", () => categoryVar(category),
Text("Edit"))}</td>
</tr>
}
Otherwise I don't see in your code where the categoryVar is being populated
other than the default (new Category()).
Derek
On Sat, Oct 11, 2008 at 1:35 PM, Charles F. Munat <[EMAIL PROTECTED]> wrote:
>
> OK, I tried that. Still no luck. I also went back to just using bind:
>
> <lift:CategoryOps.editor form="POST">
> <category:id />
> <category:name />
> <category:submit />
> </lift:CategoryOps.editor>
>
> And
>
> object categoryVar extends RequestVar(new Category())
> def category = categoryVar.is
>
> def editor(xhtml : NodeSeq) : NodeSeq = {
> def addOrUpdate() = {
> if (category.name.length == 0) {
> error("emptyCategory", "The category's name cannot be blank")
> } else {
> Model.merge(category)
> redirectTo("/admin/categories/")
> }
> }
>
> val currentId = category.id
>
>
> bind("category", xhtml,
> "id" -> SHtml.hidden({category.id = currentId}),
> "name" -> SHtml.text(category.name, category.name = _),
> "submit" -> SHtml.submit("Save", addOrUpdate))
> }
>
> Everything works just fine on add, but on update the form is not
> populated because category is a new Category, not the one from the
> database (I checked).
>
> Any ideas?
>
> Chas.
>
>
> Derek Chen-Becker wrote:
> > OK, one thing I see in your code is that your editor snippet is emitting
> > the "form" tag. You really shouldn't do it that way. The snippet tag
> > should look like
> >
> > <lift:CategoryOps.editor form="POST" />
> >
> > Otherwise I don't think the action won't get correctly populated. I
> > don't know if that would cause the form elements to not be bound as
> > well, but let's start with that.
> >
> > Derek
> >
> >
> > On Fri, Oct 10, 2008 at 5:36 PM, Charles F. Munat <[EMAIL PROTECTED]
> > <mailto:[EMAIL PROTECTED]>> wrote:
> >
> >
> > For example, here is what I get when I go to the categories list page
> > (which lists them just beautifully):
> >
> > Hibernate: select category0_.id as id2_, category0_.CREATED_AT as
> > CREATED2_2_, category0_.name as name2_, category0_.UPDATED_AT as
> > UPDATED4_2_ from CATEGORIES category0_ order by category0_.name
> > WARN - Snippet Failure: SnippetFailure(/admin/categories/ ->
> > ParsePath(List(admin, categories,
> > index),,true,true),Full(Menu.link),Stateful Snippet: Dispatch Not
> > Matched)
> > WARN - Snippet Failure: SnippetFailure(/admin/categories/ ->
> > ParsePath(List(admin, categories,
> > index),,true,true),Full(Menu.link),Stateful Snippet: Dispatch Not
> > Matched)
> > INFO - Service request (GET) /admin/categories/ took 28 Milliseconds
> > INFO - Service request (GET) /ajax_request/liftAjax.js took 1
> > Milliseconds
> >
> > So there are two warnings for each page view.
> >
> > Chas.
> >
> > David Pollak wrote:
> > > You have to define a package for Category.scala
> > >
> > > On Fri, Oct 10, 2008 at 4:00 PM, Charles F. Munat <[EMAIL PROTECTED]
> > <mailto:[EMAIL PROTECTED]>
> > > <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>> wrote:
> > >
> > >
> > > Thanks, Derek. Actually, I don't use .html or even "add" (all
> > my html
> > > files are called index.html -- I use directories to sort
> > them). This
> > > error came when I was experimenting to see if that made a
> > difference.
> > >
> > > That said, I get the error all the time. I don't have val
> > dispatch... in
> > > my snippets. But that's because I copied the JPADemo over,
> > and your
> > > AuthorOps and BookOps don't have the val dispatch either. But
> the
> > > JPADemo doesn't get this error.
> > >
> > > Also, my edit functions don't work -- the forms are not
> populated
> > > properly. I thought I had it working a minute ago, and now it
> > isn't
> > > again.
> > >
> > > I switched the snippets around a bit and dropped the bind
> > (because I
> > > wanted to color code alternate rows and wasn't sure how to do
> it
> > > otherwise). Here is an example:
> > >
> > > snippet/Category.scala:
> > >
> > > import scala.xml.{NodeSeq,Text}
> > >
> > > import net.liftweb.http.{RequestVar,S,SHtml}
> > > import net.liftweb.util.Helpers
> > > import S._
> > > import Helpers._
> > >
> > > import Model._
> > >
> > > class CategoryOps {
> > > val formatter = new java.text.SimpleDateFormat("dd MMM
> yyyy")
> > >
> > > def getRowClass(r: Int) = {
> > > if (r % 2 == 0) "even" else "odd"
> > > }
> > >
> > > def list: NodeSeq = {
> > > <tr valign="top" align="left">
> > > <th class="text">Name</th>
> > > <th class="integer">Links</th>
> > > <th class="blank"> </th>
> > > <th class="blank"> </th>
> > > </tr> ::
> > >
> > >
> >
> Model.createNamedQuery[Category]("findAllCategories").getResultList().toList.zipWithIndex.flatMap(c
> > > => <tr valign="top" class={getRowClass(c._2)}>
> > > <td class="text">{c._1.name <http://1.name>
> > <http://1.name>}</td>
> > > <td class="integer">{SHtml.link("/links/search/", {() =>
> > >
> > WeblinkOps.resultVar(Model.createNamedQuery[Weblink](
> > > "findWeblinksByCategory", "id" -> category.id
> > <http://category.id>
> > > <http://category.id>).getResultList().toList)
> > > }, Text(category.weblinks.size().toString))}</td>
> > > <td class="edit">{SHtml.link("editor", () =>
> > > categoryVar(category), Text("Edit"))}</td>
> > > <td class="delete"> </td>
> > > </tr>)
> > > }
> > >
> > > object categoryVar extends RequestVar(new Category())
> > > def category = categoryVar.is
> > >
> > > def editor (xhtml : NodeSeq) : NodeSeq = {
> > > def addOrUpdate () = {
> > > if (category.name.length == 0) {
> > > error("emptyCategory", "The category's name cannot be
> > blank")
> > > } else {
> > > Model.merge(category)
> > > redirectTo("/admin/categories/")
> > > }
> > > }
> > >
> > > val currentId = category.id <http://category.id>
> > <http://category.id>
> > >
> > > <form method="POST" action="">
> > > <table class="editor" border="0" cellpadding="3"
> > cellspacing="0">
> > > <tr valign="top" align="left">
> > > <th>Name</th>
> > > <td>{SHtml.text(category.name
> > <http://category.name> <http://category.name>,
> > > category.name <http://category.name> <http://category.name> =
> > _)}</td>
> > > </tr>
> > > <tr valign="top" align="left">
> > > <th>{SHtml.hidden({category.id <http://category.id>
> > <http://category.id> =
> > > currentId})} </th>
> > > <td>{SHtml.submit("Save", addOrUpdate)}</td>
> > > </tr>
> > > </table>
> > > </form>
> > > }
> > > }
> > >
> > > webapp/admin/categories/editor/index.html:
> > >
> > > <lift:surround with="default" at="content">
> > > <h2>Categories</h2>
> > > <table class="list">
> > > <lift:CategoryOps.list/>
> > > </table>
> > > </lift:surround>
> > >
> > > And in Boot.scala:
> > >
> > > Menu(Loc("categories", List("admin", "categories", "index"),
> > > "Categories", LocGroup("admin")),
> > > Menu(Loc("categories_add", List("admin", "categories",
> > "editor",
> > > "index"), "Add a New Category", Hidden))
> > > ),
> > >
> > > ANY suggestions for how to do any of this better greatly
> > appreciated. Do
> > > I need to add the val dispatch... part? If so, why is this
> > different
> > > from the JPADemo?
> > >
> > > Thanks!
> > > Chas.
> > >
> > >
> > > Derek Chen-Becker wrote:
> > > > It means that the dispatch function on whatever Stateful
> > Snippet is
> > > > being called isn't matching what you're asking it to
> > provide. For
> > > > instance, if your snippet tag looks like
> > > >
> > > > <lift:MySnippet.add>
> > > >
> > > > Then the dispatchPf in the MySnippet stateful snippet has
> > to have a
> > > > dispatch function like:
> > > >
> > > > val dispatch: DispatchIt = {
> > > > case "add" => <some function here> _
> > > > }
> > > >
> > > > See
> > > >
> > >
> >
> http://scala-tools.org/mvnsites-snapshots/liftweb/lift-webkit/scaladocs/index.html
> > > > for more details.
> > > >
> > > > I also know that David has recently /strongly/ recommended
> not
> > > putting
> > > > ".html" on the ends of things.
> > > >
> > > > Derek
> > > >
> > > > On Fri, Oct 10, 2008 at 3:15 PM, Charles F. Munat
> > <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> > > <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
> > > > <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> > <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>>> wrote:
> > > >
> > > >
> > > > What exactly does this mean? I get a lot of these.
> > > >
> > > > WARN - Snippet Failure:
> > SnippetFailure(/admin/users/add.html ->
> > > > ParsePath(List(admin, users, add),html,true,false),
> > > > Full(Menu.link),
> > > > Stateful Snippet: Dispatch Not Matched)
> > > >
> > > > What is failing here and what are the probable causes?
> > > >
> > > > Thanks.
> > > >
> > > > Chas.
> > > >
> > > >
> > > >
> > > >
> > > > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > Lift, the simply functional web framework http://liftweb.net
> > > Collaborative Task Management http://much4.us
> > > Follow me: http://twitter.com/dpp
> > > Git some: http://github.com/dpp
> > >
> > > >
> >
> >
> >
> >
> > >
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---