I have the following rewrite in Boot.boot(). This is based on the instructions found in the URL Rewriting section in the Lift Wiki.
LiftRules.statefulRewrite.prepend(NamedPF("CreateAndEditRewrite") {
case RewriteRequest(
ParsePath("models" :: "createEdit" :: state :: Nil, _, _,_), _, _) => {
Console.println("Rewriting path: models/createEdit/Create to createEdit.html")
val rewriteResp = RewriteResponse(
"models/createEdit" :: Nil, "html" // Use webapp/models/creteEdit.html
)
Console.println("Response refers to URL " + rewriteResp.path + " with parameters " + rewriteResp.params.toList.map(x => "" + x.key + "=" + x.value + ", "))
rewriteResp
}
})
To make sure everything is accessible a made sure SiteMap permitted access to “models/createEdit/create” and “models/createEdit” with the following lines.
val entries =
Menu(Loc("models", List(""), "Models"),
Menu(Loc("createEditM", List("models","createEdit","Create"), "[NEW]Create Model", loggedIn)),
Menu(Loc("createEditMXX", List("models","createEdit"), "[NEW]Create Model", loggedIn)) ) ::
User.sitemap
// Build SiteMap
LiftRules.setSiteMap(SiteMap(entries:_*))
LiftRules.passNotFoundToChain = true //if a URL isn't found pass responsability to the container
Yet, the second menu option works while the first yelds a “HTTP ERROR 404
Problem accessing /models/createEdit/Create” on the container level.
The following println appear on the console
Rewriting path: models/createEdit/Create to createEdit.html
Response refers to URL ParsePath(List(models/createEdit),html,true,false) with parameters List()
INFO - Service request (GET) /models/createEdit/Create returned 0, took 11 Milliseconds
which means the rewrite was triggered.
I’m using Lift 2.4-M3 with Scala 2.9.0-1.
Anyone has any idea what is the problem?
Thanks.
Edit: changed code sample and added console output to make what is happening clearer.
First, don’t use the Rewrite stuff. It’s low level and generally isn’t necessary.
If you want a parameterized Menu entry, use Menu.param. See http://simply.liftweb.net/index-3.2.html#toc-Subsection-3.2.7