[Lift] Re: About the url rewrite (more thant one params and get 404 not found error)

2010-03-01 Thread Neil.Lv
OK, Got it, Thank you very much!

On Mar 2, 3:01 am, David Pollak  wrote:
> On Sun, Feb 28, 2010 at 8:28 PM, Neil.Lv  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 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.
>
> --
> 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 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.



[Lift] Re: About the url rewrite (more thant one params and get 404 not found error)

2010-03-01 Thread Neil.Lv

  I add these code in the Boot class, but it doesn't work.

  How can write the correct code to parse the url ?

#
object ParamsExtractor {
  def unapply(pp: ParsePath): Option[(String)] = {
Log.info("wholePath: " + pp.wholePath)
val path = List("test")
val result:Box[(String)] = if (pp.wholePath.startsWith(path) &&
pp.wholePath.length == (path.length + 2)) {
  val res = Full(("test2"))
Log.info("Decoded URL: %s=%s".format(pp, res))
res
} else None
Log.info("result: " + result)
result
  }
}

class Boot {
  def boot {
...
LiftRules.statelessRewrite.prepend {
 case RewriteRequest(ParamsExtractor(param) , _, _) =>
   RewriteResponse(List("test"), Map("param" -> param))
}
...
  }
}
#

  Thanks!~~

Cheers,
  Neil

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



[Lift] Re: About the url rewrite (more thant one params and get 404 not found error)

2010-03-01 Thread Neil.Lv


On Mar 1, 5:10 pm, Jeppe Nejsum Madsen  wrote:
> Ahh yes, the example was from a Loc rewrite, The principle is the same I
> guess, you should be able to do something like this:
>
> case RewriteRequest(ParamsExtractor(account,orgUnit) , _, _) =>
>   RewriteResponse(path, Map("account" -> account, "orgUnit" -> orgUnit))
>
> The important part is the extractor which takes care of parsing the
> request into meaningful values...
>
> /Jeppe

  Got it, thanks for your reply.

  I'll  try it later.

  :)

Cheers,
  Neil

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



Re: [Lift] Re: About the url rewrite (more thant one params and get 404 not found error)

2010-03-01 Thread Jeppe Nejsum Madsen
"Neil.Lv"  writes:

> On Mar 1, 3:53 pm, Jeppe Nejsum Madsen  wrote:
>>
>> 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))
>
>   I have some question about these code that i don't understand.
>
>   The first one that contains the Map() in the RewriteResponse() .
>-->
>case RewriteRequest() => RewriteResponse()
>
>   but the second one that doesn't contain the Map in the
> RewriteResponse(),
>   what's the mean of the Full(account, orgUnit) in the
> ( RewriteResponse(path), Full(account, orgUnit) )
>-->
>case RewriteRequest() => ( RewriteResponse(), Full() )


Ahh yes, the example was from a Loc rewrite, The principle is the same I
guess, you should be able to do something like this:

case RewriteRequest(ParamsExtractor(account,orgUnit) , _, _) =>
  RewriteResponse(path, Map("account" -> account, "orgUnit" -> orgUnit))

The important part is the extractor which takes care of parsing the
request into meaningful values...

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



[Lift] Re: About the url rewrite (more thant one params and get 404 not found error)

2010-03-01 Thread Neil.Lv


On Mar 1, 3:53 pm, Jeppe Nejsum Madsen  wrote:
>
> 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))

  I have some question about these code that i don't understand.

  The first one that contains the Map() in the RewriteResponse() .
   -->
   case RewriteRequest() => RewriteResponse()

  but the second one that doesn't contain the Map in the
RewriteResponse(),
  what's the mean of the Full(account, orgUnit) in the
( RewriteResponse(path), Full(account, orgUnit) )
   -->
   case RewriteRequest() => ( RewriteResponse(), Full() )

###

  case RewriteRequest(
  ParsePath(List("show", "img", version, id), _, _,_), _, _) =>
RewriteResponse(List("show", "img"),
  Map("version" -> version, "id" -> id)
)


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

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