OK, Got it, Thank you very much!

On Mar 2, 3:01 am, David Pollak <[email protected]> wrote:
> On Sun, Feb 28, 2010 at 8:28 PM, Neil.Lv <[email protected]> wrote:
> > Hi all,
>
> >  I have a silly question about the url rewrite in the lift.
> >  It has another two params in the url after the img.
>
> >  http://localhost:8080/show/img/version/id
>
> >  The url works fine.
> >  =>http://localhost:8080/show/img
> >  =>http://localhost:8080/show/img/v1/
> >  =>http://localhost:8080/show/img/v1/1
>
> >  Get 404 error if the "/" string is not added at the end of the url
> > (the id param isn't supplied)
> >  =>http://localhost:8080/show/img/v1
>
> >  So, how can i rewrite the url and set the sitemap can make this link
> > (  http://localhost:8080/show/img/v1 )
> >  works fine as (  http://localhost:8080/show/img/v1/ ) when the id
> > is not supplied.
>
> >  Here is the code:
>
> > ###
> >  case RewriteRequest(
> >      ParsePath(List("show", "img", version, id), _, _,_), _, _) =>
> >    RewriteResponse(List("show", "img"),
> >      Map("version" -> version, "id" -> id)
> >  )
> > ###
>
> This is just basic pattern matching stuff.  So,
>
> case RewriteRequest(
>      ParsePath("show" :: "img" :: version :: rest, _, _,_), _, _) =>
> RewriteResponse(List("show", "img"),
>      Map("version" -> version, "id" -> (rest.firstOption getOrElse "N/A"))
>  )
>
> Please pick up a copy of one of the Scala books and look at the pattern
> matching section related to Lists.  There's a lot of flexibility that's no
> Lift-specific, but that Lift leverages.
>
> val entries = Menu(Loc("Home", List("index"), "Home")) ::
>
>
>
> > Menu(Loc("show", List("show"), "show", Hidden)) :: User.sitemap
>
> > ###
>
> >  BTW, I use the LiftView to handle the request.
>
> > ###
> > class show extends LiftView {
> >  def dispatch = {
> >    case "img" => imgDispatch _
> >    case _ => allDispatch _
> >  }
>
> >  def imgDispatch(): Box[NodeSeq] = {
> >    ...
> >  }
>
> >  def allDispatch(): Box[NodeSeq] = {
> >    ...
> >  }
> > }
> > ###
>
> >  Thanks very much!
>
> > Cheers,
> >  Neil
>
> > --
> > 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 frameworkhttp://liftweb.net
> Beginning Scalahttp://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