Hi Philip, thanks for the response.

That looks relevant to what i'm doing... but I think the key thing I'm
looking for is for the case not to match if the product does not exist
for that manufacturer, so I can show a 404.  I think Jeppe's approach
will work well.

I'm not 100% following your example, but it looks to me like your case
statements always match /page/level1/level2 etc without a check like
does this particular level 2 (say "foo") make sense for this level1
("bar"), but maybe I misunderstood.

- Alex

On Feb 6, 8:25 pm, philip <[email protected]> wrote:
> Hi Alex,
>
> I am making a CMS, so I had to get database content for any page up to
> 4 levels under the URLhttp://site/page/leve1/level2/etc... Here is
> some example code from this:
>
> class Boot {
>   def selectTemplate(template: String, subPages: List[String]):
> RewriteResponse =
>     {
>       var levels = Map() ++ (List[String]("level1", "level2",
> "level3", "level4") zip subPages)
>       levels = levels + ("totalLevels" -> levels.size.toString)
>       RewriteResponse(template :: Nil, levels)
>     }
>
>   def boot {
> ... lots of stuff
>
>     LiftRules.rewrite.prepend(NamedPF("inner pages")
>         {
>           case RewriteRequest(ParsePath("page" :: subPages, _, _, _),
> _, _) => selectTemplate("innerpage", subPages)
>           case RewriteRequest(ParsePath("intercitizen" :: subPages, _,
> _, _), _, _) => selectTemplate("intercitizentemplate", subPages)
>         })
>
> This means that anything that goes tohttp://site/page/one/twogoes to
> a file called innerpage.html and the innerpage.html contains
>
> <lift:surround with="default" at="content">
> <div style="margin-left:15px !important; margin-right:15px !important;
> margin-top:8px !important;">
>       <lift:Content.display>
>       </lift:Content.display>
> </div>
> </lift:surround>
>
> And the snippit contains
>
> package com.orsa.iom3.snippet
>
> import xml.{Text, NodeSeq}
> import net.liftweb.http.S
> import com.orsa.iom3.model.SiteContent
> import net.liftweb.util.{Log, Helpers}
> import com.orsa.util.Constants
>
> /**
>  */
>
> class Content
> {
>   def display(in: NodeSeq): NodeSeq =
>     {
>       //val name = S.attr("name") openOr "0"
>
>       // Get the site content from the database
>       val totalLevels:String = S.param("totalLevels") openOr "0"
>       // Build the path for the levels
>       var path = Constants.CMS_ROOT_PATH
>       for (i <- 1 to totalLevels.toInt)
>         path = path + Constants.CMS_PATH_SEP + S.param("level" +
> i).openOr("0")
>
>       val content:SiteContent = SiteContent.findByUniqueName(path)
> openOr new SiteContent
>       // Return the content inside a DIV
>       <div>{scala.xml.Unparsed(content.page_Content_Html.toString)}</
> div>
>     }
>
> }
>
> On 2月6日, 上午9時14分, Alex Black <[email protected]> wrote:
>
>
>
> > Hi, I'd like to rewrite a url like this:
>
> > /manufacturer/product
>
> > e.g.
>
> >     LiftRules.statelessRewrite.append( {
> >       case RewriteRequest(
> >         ParsePath( manufacturerName :: productName :: Nil, _, _,_), _,
> > _)  =>
>
> >         RewriteResponse("productView" :: Nil)
> >     })
>
> > But, I'd like to the ParsePath case to not 'catch' for non-existant
> > manufacturers, and non-existant products by the manufacturer.
>
> > So, I might do this:
>
> >     LiftRules.statelessRewrite.append( {
> >       case RewriteRequest(
> >         ParsePath( Manufacturer(manufacturer) :: Product(product) ::
> > Nil, _, _,_), _, _)  =>
>
> >         RewriteResponse("productView" :: Nil)
> >     })
>
> > Where Manufacturer and Product objects provide an extractor which does
> > a lookup.
>
> > However, the product lookup depends on the manufacturer.. is there a
> > way to handle that?
>
> > ideas:
> > 1. use an if guard
>
> >       case RewriteRequest(
> >         ParsePath( Manufacturer(manufacturer) :: productName :: Nil,
> > _, _,_), _, _)  if manufacturer.contains(productName) =>
> >           val product = manufacturer.getProduct(productName)
>
> > sucks because it looks up the product twice.
>
> > 2. some time of nested case?
>
> >       case RewriteRequest(
> >         ParsePath( Manufacturer(manufacturer) :: Product(manufacturer,
> > product) :: Nil, _, _,_), _, _)  =>
>
> > obviously doesn't work..
>
> > any suggestions welcome, thanks!
>
> > - Alex

-- 
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.

Reply via email to