In the recent thread, a couple people asked for the ability to create dynamic menu items per request from the database. David suggested Loc.supplimentalKidMenuItems which works fine for dynamic children of a static menu, but doesn't support the ability to make the top level menu dynamic.
Menu has a method called "makeMenuItem" which gives a Box of MenuItem. What about a new method makeMenuItems that gives a possible plurality of MenuItems whose default implementation deferred to the existing makeMenuItem in the case where it's not overridden? I made this change to my local copy of lift and it seems to work alright. Example Menu: case class DynMenu() extends Menu(Loc("dynmenu", Link(List("dynmenu"), true, "/dynmenu"), "Dynamic Menu")) { override def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = DynMenuItem.findAll.map(dmi => { MenuItem(Text(dmi.label.is), Text(dmi.link.is), Nil, false, false, Nil) }) } That is, a Menu can generate 0 or more MenuItems when the menu is being generated. The disadvantage I see is similar to the one with supplimentalKidMenuItems -- that is, you have to manually compute the attributes of MenuItem such as current. However, it does give you the full power to make whatever kind of menu items you want. I looked briefly at seeing if it would be feasible to use a function Box[Req] => SiteMap on LiftRules, but I think the RewritePF auto detection thing in LiftRules.setSiteMap prevents this from being the right thing. The change to lift-webkit: diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala index d33d1dc..79194f5 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/Menu.scala @@ -61,8 +61,10 @@ case class Menu(loc: Loc[_], kids: Menu*) extends HasKids { } // def buildChildLine: List[MenuItem] = kids.toList.flatMap(m => m.loc.buildItem(Nil, false, false)) + def makeMenuItems(path: List[Loc[_]]): Iterable[MenuItem] = makeMenuItem(path) + def makeMenuItem(path: List[Loc[_]]): Box[MenuItem] = - loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) + loc.buildItem(loc.buildKidMenuItems(kids), _lastInPath(path), _inPath(path)) private def _inPath(in: List[Loc[_]]): Boolean = in match { case Nil => false diff --git a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala index 7939938..f8fa307 100644 --- a/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala +++ b/lift-base/lift-webkit/src/main/scala/net/liftweb/sitemap/SiteMap.scala @@ -66,7 +66,7 @@ case class SiteMap(globalParamFuncs: List[PartialFunction[Box[Req], Loc.AnyLocPa case Full(loc) => loc.breadCrumbs case _ => Nil } - CompleteMenu(kids.flatMap(_.makeMenuItem(path))) + CompleteMenu(kids.flatMap(_.makeMenuItems(path))) } } Thoughts? -Ross -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=.