Folks,

Please keep in mind that RequestMemoize is made for use with extractors...
you only need to make RDBMS requests once per request even if the extractor
is called multiple times with the same value.

Thanks,

David

On Sat, Feb 6, 2010 at 5: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 URL http://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 to http://site/page/one/two goes 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]<liftweb%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
>
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

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