eje211
eje211

Reputation: 2429

In Lift, changing the way Menu.param behaves

EDIT: I just realized that my problem is not that the example doesn't work! It's that the page does not appear in the menu! Plus, how can I handle the page with no parameters?

I'm having a hard time finding a generic definition of Menu.param. There's the example in Simply Lift and a few references to code in this forum, but the feature is important and still, as much as I can tell, not very well documented.

Right now, I'm having a problem with my sitemap. Anything I declare in the sitema Boot.scala and the code seems to be accepted but then ignored. localhost:8080/journal leads to a 404 and the menu item "Autobiography" does not appear in the sitemap.

So, on the one hand, this post is a call for help for this code. Why is it being ignored? (Again, it compiles and is executed with no errors.)

On the other hand, is it just me or is "param" undocumented outside of David Pollack's examples? It's not in the API: http://main.scala-tools.org/​mvnsites/liftweb-2.0/​framework/scaladocs/net/​liftweb/sitemap/Menu$object.​html.

Thanks.

This is my sitemap. I added the Param example from Simply Lift just to see if it worked. It doesn't.

def sitemap = SiteMap(
  Menu.i("Home") / "index" >> User.AddUserMenusAfter, // the simple way to declare a menu
  Menu.i("Artifact") / "artifact", // Works
  // Menu.i("Autobiography") / "journal", // Works if I comment out the next line.
  AutobiographyPageMenu.menu,
  Menu.param[AutobiographyPage](​"Autobiography2", "Autobiography2", // Similar code as previous line. Doesn't work.
                                pageName => Full(AutobiographyPage(​pageName)),
                                ap => ap.pageName) / "journal2",
  Param.menu, // Added to see if D. Pollack's code would work. It didn't.

  // more complex because this menu allows anything in the
  // /static path to be visible
  Menu(Loc("Static", Link(List("static"), true, "/static/index"),
           "Static Content")))

This is the code it refers to, from a file in a snippet sub-package. Lift can find the classes: it does not complain about them not being defined.

case class AutobiographyPage(pageName: String)

object AutobiographyPageMenu {

  val menu = Menu.param[AutobiographyPage](​"Autobiography", "Autobiography",
                                           pageName => Full(AutobiographyPage(​pageName)),
                                           ap => ap.pageName) / "journal"
  // I'm not sure what these two lines are for...
  lazy val loc = menu.toLoc
  def render = "*" #> loc.currentValue.map(_.​pageName)
}

// This code is copied from the Simply Lift book:

// capture the page parameter information
case class ParamInfo(theParam: String)

// a snippet that takes the page parameter information
class ShowParam(pi: ParamInfo)  {
  def render = "*" #> pi.theParam
}

object Param {
  // Create a menu for /param/somedata
  val menu = Menu.param[ParamInfo]("Param", "Param",
                                   s => Full(ParamInfo(s)),
                                   pi => pi.theParam) / "param"
  lazy val loc = menu.toLoc

  def render = "*" #> loc.currentValue.map(_.​theParam)
}

Upvotes: 2

Views: 587

Answers (1)

Brian Hsu
Brian Hsu

Reputation: 8821

As you can see, you have two menu references to same path:

// Menu.i("Autobiography") / "journal", // Works if I comment out the next line.


val menu = Menu.param[AutobiographyPage](
  ​"Autobiography", "Autobiography", 
  pageName => Full(AutobiographyPage(​pageName)),
  ap => ap.pageName) / "journal"

They both match http://localhost/journal, and have same menu id "Autobiography", that's why it does not work.

You may try to change menu id "Autobiography" in AutobiographyPageMenu.param to see if it work.

Upvotes: 1

Related Questions