4.9 But sometimes Old Fashioned is good
In this chapter, we’ve explored Lift’s form building and processing features and demonstrated the power and value of associating GUIDs on the client with functions on the server. However, sometimes it’s nice to have parameter processing via URL parameters... and that’s easy to do with Lift as well.
Every page in the examples for this chapter contain:
<form action="/query">
<input name="q">
<input type="submit" value="Search">
</form>
This is a plain old form that generates a URL like: http://localhost:8080/query?q=catfood This URL can be copied, pasted, shared, etc.
Processing this URL is easy:
Query.scala
package code
package snippet
import net.liftweb._
import http._
import util._
import Helpers._
object Query {
def results = ClearClearable andThen
"li *" #> S.param("q"). // get the query parameter
toList. // convert the Box to a List
flatMap(q => {
("You asked: "+q) :: // prepend the query
(1 to toInt(q)).toList.map(_.toString) // if it can be converted to an Int
// convert it and return a sequence of Ints
})
}
Using S.param("param_name") we can extract the query parameter and do something with it.
(C) 2012 David Pollak