paramitized menus

93 views
Skip to first unread message

bishop155

unread,
Jul 21, 2011, 7:15:55 PM7/21/11
to Lift
I want to create a Menu which has multiple items which differ in only
the parameter passed. I'm pritty close:

case class Test(id: String);

var test = Menu.param[Test]("Test-1", "Test-1",
s => {Full(Test(s))},
pi =>{
pi.id
}
) / "category" / * >> Loc.CalcValue(() => { Box(Test("1")) } )>>
Loc.Template(() =>
TemplateFinder.findAnyTemplate(List("category")).openOr(<div>Template
not found</div>) );

var test2 = Menu.param[Test]("Test-2", "Test-2",
s => {
Full(Test(s))
},
pi => {
pi.id
}
) / "category" / * >> Loc.CalcValue(() => Box(Test("2")) )>>
Loc.Template(() =>
TemplateFinder.findAnyTemplate(List("category")).openOr(<div>Template
not found</div>) );

val entities = test :: test2 :: Nil;

SiteMap.enforceUniqueLinks = false;

But it always matches the first menu item, and never the second. is
there a way I can change the doesMatch_? function? (Ive successfully
managed to achieve this by writing a custom loc, wondering if theres
another/better way to do it?)

David Pollak

unread,
Jul 25, 2011, 5:13:51 AM7/25/11
to lif...@googlegroups.com
You can only have 1 menu entry per URL.  You cannot do what you're trying to do.  Sorry.


--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net

Naftoli Gugenheim

unread,
Jul 25, 2011, 9:17:47 PM7/25/11
to lif...@googlegroups.com
Maybe one day, the menu hierarchy as rendered by the menu snippet should be decoupled from the set of menu entries that define the SiteMap itself (as used for page access etc.), with the rendered tree defaulting to the same as the actual SiteMap. This way, the SiteMap implementation remains the same, but there's much greater flexibility (for those that want to write the explicit code) in terms of how to display it.

David Pollak

unread,
Jul 26, 2011, 12:32:27 AM7/26/11
to lif...@googlegroups.com
On Tue, Jul 26, 2011 at 3:17 AM, Naftoli Gugenheim <nafto...@gmail.com> wrote:
Maybe one day, the menu hierarchy as rendered by the menu snippet should be decoupled from the set of menu entries that define the SiteMap itself (as used for page access etc.), with the rendered tree defaulting to the same as the actual SiteMap. This way, the SiteMap implementation remains the same, but there's much greater flexibility (for those that want to write the explicit code) in terms of how to display it.

That'd be great.

Given that the Menu snippets could be user-written code, there's nothing magic about them.  If we see patterns of usage that go beyond the current implementation, I'm all for enhancing the existing snippets or adding snippets to reflect those patterns... but so far, I haven't seen patterns... but if others are seeing the patterns, let's reduce them to enhancements/additions to the existing menu/sitemap snippets.
 

bishop155

unread,
Jul 31, 2011, 5:51:26 PM7/31/11
to Lift
They is one entry per url I'm trying to achieve (/category/1, /
category/2), seams abit strange (to me) that the Loc isnt decoupled
from the menu, so the the loc should match /category/*, but the menus
be able to point to that Loc with a paramaters, IE /category/1 & /
category/2.

I am a novice with lift, I come from a zend framework background which
lets me do the described above very easily, which leads me to believe
I'm doing it wrong or Im missing the point.

The Loc.Link class seams abit overloaded to me, it used for a)
generating the url, b) finding the template and c) matching the
request. This seams to leave the only option is to write a custom Loc,
where you specify the different Loc parameters separately?

I greatly appreciate your help.

On Jul 26, 5:32 am, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> On Tue, Jul 26, 2011 at 3:17 AM, Naftoli Gugenheim <naftoli...@gmail.com>wrote:
>
> > Maybe one day, the menu hierarchy as rendered by the menu snippet should be
> > decoupled from the set of menu entries that define the SiteMap itself (as
> > used for page access etc.), with the rendered tree defaulting to the same as
> > the actual SiteMap. This way, the SiteMap implementation remains the same,
> > but there's much greater flexibility (for those that want to write the
> > explicit code) in terms of how to display it.
>
> That'd be great.
>
> Given that the Menu snippets could be user-written code, there's nothing
> magic about them.  If we see patterns of usage that go beyond the current
> implementation, I'm all for enhancing the existing snippets or adding
> snippets to reflect those patterns... but so far, I haven't seen patterns...
> but if others are seeing the patterns, let's reduce them to
> enhancements/additions to the existing menu/sitemap snippets.
>
>
>
>
>
>
>
>
>
>
>
> > On Mon, Jul 25, 2011 at 5:13 AM, David Pollak <
> > feeder.of.the.be...@gmail.com> wrote:
>
> >> You can only have 1 menu entry per URL.  You cannot do what you're trying
> >> to do.  Sorry.
>
> >> Simply Lifthttp://simply.liftweb.net
> >> Follow me:http://twitter.com/dpp
> >> Blog:http://goodstuff.im
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "Lift" group.
> >> To post to this group, send email to lif...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> liftweb+u...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/liftweb?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Lift" group.
> > To post to this group, send email to lif...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > liftweb+u...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/liftweb?hl=en.
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Simply Lifthttp://simply.liftweb.net

David Pollak

unread,
Aug 1, 2011, 3:41:14 AM8/1/11
to lif...@googlegroups.com
On Sun, Jul 31, 2011 at 11:51 PM, bishop155 <chrisjb...@gmail.com> wrote:
They is one entry per url I'm trying to achieve (/category/1, /
category/2), seams abit strange (to me) that the Loc isnt decoupled
from the menu, so the the loc should match /category/*, but the menus
be able to point to that Loc with a paramaters, IE /category/1 & /
category/2.

Loc and Menu are in fact and intentionally intertwined.  I do not see why this is a problem.

If you want to generate a URL from a Loc, use the createLink method which is type-safe.  You can display all manner of generated links on the page where-ever you what, however you want.
 

I am a novice with lift, I come from a zend framework background which
lets me do the described above very easily, which leads me to believe
I'm doing it wrong or Im missing the point.

The Loc.Link class seams abit overloaded to me, it used for a)
generating the url, b) finding the template and c) matching the
request. This seams to leave the only option is to write a custom Loc,
where you specify the different Loc parameters separately?

Did you look at Menu.param or Menu.params?  See http://simply.liftweb.net/index-Chapter-3.html#toc-Chapter-3 and http://simply.liftweb.net/index-3.2.html#toc-Section-3.2

If you can describe your use case, it would have getting you to the answer you want rather than trying to map your existing knowledge onto Lift.
 



--
Lift, the simply functional web framework http://liftweb.net

Jack Park

unread,
Aug 1, 2011, 4:12:25 PM8/1/11
to lif...@googlegroups.com
http://simply.liftweb.net/index-3.2.html#toc-Subsection-3.2.7 box
3.2.7 shows code that is presumably in Boot.scala, although it's
difficult to picture how that snippet of code, a class and a val, fit
into the grand scheme of creating a sitemap. Then
http://simply.liftweb.net/index-3.4.html#sub:Param-Example shows a
snippet class that duplicates the ParamInfo class.

Trying to replicate the 3.2.7 code in my Boot.scala required that I
put ParamInfo there just as illustrated since the compiler did not
find it in the Param.scala code I also replicated.

Since it is difficult to understand how that snippet fits inside
sitemap creation, I've not been able to coax the code to work:
specifically, I get an error when I put the snippet
<span class="lift:ShowParam">???</span>
in my html: Class Not Found

Is there a link to a project that does parameterized menus from which
one can see the entire lifecycle?

Thanks
Jack

bishop155

unread,
Aug 1, 2011, 5:55:29 PM8/1/11
to Lift
My apologize,

What I am trying to do is have a menu of categories, which all use the
same template, but which each have an individual menu item for each
category, ie:
/category/1 & /category/2 in the menu.

The Param menu from my original example, doesn't correctly match the
active menu item (always matches the first item regardless of the
parameter provided).

Yer I have looked at Menu.param, which I have attempted to use if you
see my original example. But I ran into the problem described in the
paragraph above.

I hope I managed to explain things a bit clearer, thank you for your
time.

On Aug 1, 8:41 am, David Pollak <feeder.of.the.be...@gmail.com> wrote:
> On Sun, Jul 31, 2011 at 11:51 PM, bishop155 <chrisjbishop...@gmail.com>wrote:
>
> > They is one entry per url I'm trying to achieve (/category/1, /
> > category/2), seams abit strange (to me) that the Loc isnt decoupled
> > from the menu, so the the loc should match /category/*, but the menus
> > be able to point to that Loc with a paramaters, IE /category/1 & /
> > category/2.
>
> Loc and Menu are in fact and intentionally intertwined.  I do not see why
> this is a problem.
>
> If you want to generate a URL from a Loc, use the createLink method which is
> type-safe.  You can display all manner of generated links on the page
> where-ever you what, however you want.
>
>
>
> > I am a novice with lift, I come from a zend framework background which
> > lets me do the described above very easily, which leads me to believe
> > I'm doing it wrong or Im missing the point.
>
> > The Loc.Link class seams abit overloaded to me, it used for a)
> > generating the url, b) finding the template and c) matching the
> > request. This seams to leave the only option is to write a custom Loc,
> > where you specify the different Loc parameters separately?
>
> Did you look at Menu.param or Menu.params?  Seehttp://simply.liftweb.net/index-Chapter-3.html#toc-Chapter-3andhttp://simply.liftweb.net/index-3.2.html#toc-Section-3.2

David Pollak

unread,
Aug 26, 2011, 6:26:51 PM8/26/11
to lif...@googlegroups.com
Please see http://simply.liftweb.net/index-6.3.html#toc-Section-6.3  Specifically the AllItemsPage.scala snippet:

  // for a list of items, display those items
  def renderItems(in: Seq[Item]) =
    "tr" #> in.map(item => {
      "a *" #> item.name &
      "a [href]" #> AnItemPage.menu.calcHref(item) &
      "@description *" #> item.description &
      "@price *" #> item.price.toString &
      "@add_to_cart [onclick]" #>
      SHtml.ajaxInvoke(() => TheCart.addItem(item))})

Note the mapping from Item to HREF via AnItemPage.menu.calcHref(item)
Lift, the simply functional web framework http://liftweb.net
Reply all
Reply to author
Forward
0 new messages