"Neil.Lv" <anim...@gmail.com> writes:

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


I'm not sure if this can be handled with the standard ParsePath, but it
is fairly easy to write your own extractor that can handle more complex
scenarios. Here's an example:

object ParamsExtractor {
      def unapply(pp:ParsePath): Option[(Account, OrgUnit)] = {
        val result:Box[(Account, OrgUnit)] = if (pp.wholePath.startsWith(path) 
&& pp.wholePath.length == (path.length + 2)) {
          val res = Full((XX,YY))
          debug("Decoded URL: %s=%s".format(pp,res))
          res
          }
        else
          None
        result
      }
    }
used like this:

case RewriteRequest(ParamsExtractor(account,orgUnit) , _, _) =>
(RewriteResponse(path), Full(account, orgUnit))

/Jeppe

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

Reply via email to