Trying out MatchWithoutCurrentValue

46 views
Skip to first unread message

Richard Dallaway

unread,
Jan 14, 2015, 8:16:41 AM1/14/15
to lif...@googlegroups.com
Hello!

I’m working through some of the new features in 2.6, and I’m having difficulty getting MatchWithoutCurrentValue working as I expect.

I have a database of products, containing one product. It has an ID of 1.  I have a menu param for /product/{id}:

lazy val product = Menu.param[ProductInfo]("product", "Product Detail Page",
  id => lookup(id),
  info => info.id.toString
  ) / "product" >> MatchWithoutCurrentValue >> FallbackToSearchPage

 val FallbackToSearchPage = IfValue[ProductInfo](_.isDefined, () => RedirectResponse("/"))

There’s more code for the case class and fake database lookup etc.  The full example is: https://github.com/d6y/MatchWithoutCurrentValueExample

I’m expecting the combination of MatchWithoutCurrentValue and FallbackToSearchPage to mean that a request for /product/2 (I don’t have a 2) should redirect me to the site’s home page. But instead it 404s me the way Menu.param normally would.

I’ve misunderstood or I’m misusing something. Help! :-)

Cheers
Richard


Matt Farmer

unread,
Jan 14, 2015, 9:35:23 AM1/14/15
to Lift
Yeah, that looks a bit weird. Let me try to find some time this afternoon to poke this and see if I can’t figure out what’s up.


Matt Farmer Blog | Twitter

--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Diego Medina

unread,
Jan 14, 2015, 10:01:16 AM1/14/15
to Lift
looking at the source code, _.isDefined will still give you false, the only thing that changes when yo uadd that loc is the result of def doesMatch_?


Haven't looked at how to access the Req from the menu

Thanks

Diego


--
Diego Medina
Lift/Scala consultant
di...@fmpwizard.com
http://fmpwizard.telegr.am

Matt Farmer

unread,
Jan 15, 2015, 3:21:49 PM1/15/15
to Lift
I’m pretty sure returning .isDefined as false is the desirable behavior here Diego… 


Matt Farmer Blog | Twitter

Matt Farmer

unread,
Jan 15, 2015, 3:36:27 PM1/15/15
to Lift
Alright Richard, I think I’ve got something for you:

If I change your menu definition to:

    val product = Menu.param[ProductInfo]("product", "Product Detail Page",
      id   => lookup(id),
      info => info.id.toString
    ) / "product" / * >> MatchWithoutCurrentValue >> FallbackToSearchPage >>
    TemplateBox(() => Templates("product" :: Nil))

Things start working as expected.

It looks like the * is required for some reason. There’s probably another codepath that doesn’t check for the MatchWithoutCurrentValue flag on a Loc. I’ll file a bug to look at it when I have time at some point.


Matt Farmer Blog | Twitter

Richard Dallaway

unread,
Jan 16, 2015, 4:17:05 AM1/16/15
to lif...@googlegroups.com, Lift
Great - thank you.

It also works if I rename products.html to be products/star.html after adding in the / * part of the Menu.param

Cheers
Richard

Matt Farmer

unread,
Feb 14, 2015, 1:05:27 PM2/14/15
to lif...@googlegroups.com
Ok, folks, the plot thickens a bit.

I did some investigation here and Diego is correct: isDefined is returning false so the MatchWithoutCurrentValue bit never gets checked. It's returning false because we hit the case where we're checking the matchHead_? property of the Link, but that never gets set to true by anything.


We're officially in "I'm not sure how this ever worked" territory. Does anyone remember under what conditions that boolean was supposed to be set to true by the Framework or is that something that the user has to do somehow?

Antonio Salazar Cardozo

unread,
Feb 14, 2015, 4:22:32 PM2/14/15
to lif...@googlegroups.com
Looks like matchHead_? has to be explicitly set to true when you're constructing your menu; e.g.:

Menu.param[Boom]("hi", LinkText("hi", false), ...)

Or:

Menu.param[Boom]("hi", ("hi", false), ...)

Thanks,
Antonio

Antonio Salazar Cardozo

unread,
Feb 14, 2015, 4:29:13 PM2/14/15
to lif...@googlegroups.com
And to clarify, I believe that condition is:
 - The path we're checking is not empty.
 - The path this Loc describes is supposed to be empty.

In this case, we only match if the Loc says that we can match any subpath under
the Loc's path, since if the Loc requires a precise match and we're checking a
non-empty path against an empty one, it fails by definition.
Thanks,
Antonio

Matt Farmer

unread,
Mar 21, 2015, 4:56:16 PM3/21/15
to lif...@googlegroups.com
LinkText only accepts one argument dude. It's Link that lets you set matchHead. I still don't see a way from our API to ever set matchHead to true...

It looks like it's set to false when a PreParamMenu becomes a ParamMenuable and never set to true... which is to say I'm not sure how omitting the * ever works.

Antonio Salazar Cardozo

unread,
Mar 21, 2015, 5:03:32 PM3/21/15
to lif...@googlegroups.com
Yah, my bad, that was Link, not LinkText. http://liftweb.net/api/26/api/#net.liftweb.sitemap.Loc$$Link$ 

which in turn uses this:

pathElement.endsWith("**")

So it looks like matchHead is true when you're doing a deep wildcard match, but not when you're
matching a direct child.
Thanks,
Antonio

Matt Farmer

unread,
Jul 24, 2015, 5:57:50 PM7/24/15
to Lift, savedf...@gmail.com
Woooooooooooooo.

This was a doozy, but I think we finally have a fix. I've opened this pull request with it: https://github.com/lift/framework/pull/1714

Net-net: We handle non-starred Menu.param's differently and now that pipeline is aware of the MatchWithoutCurrentValue LocParam. So this will certainly be fixed in Lift 3, however I had to change some things that are public-ish to fix it... so I'm not sure what we want to do for the Lift 2.x series... in theory someone could have pulled an instance of LocRewrite out of their hat and be depending on it, I think.

Thoughts?

Richard Dallaway

unread,
Jul 25, 2015, 9:04:03 AM7/25/15
to Lift, savedf...@gmail.com
Nice work. Personally, I don't need this back ported to Lift 2.6.

--

Antonio Salazar Cardozo

unread,
Jul 25, 2015, 10:22:10 AM7/25/15
to Lift, ric...@dallaway.com, ric...@dallaway.com
Come to think of it, we don't currently have any more 2.x feature releases planned
anyway, so I'd say punt on it.
Thanks,
Antonio

Matt Farmer

unread,
Jul 25, 2015, 12:24:06 PM7/25/15
to Lift
Ah, I suppose that’s true. Sounds good.

🍻


Matt Farmer Blog | Twitter
Reply all
Reply to author
Forward
0 new messages