Skip to content

Instantly share code, notes, and snippets.

@dph01
Created March 26, 2012 14:51
Show Gist options
  • Save dph01/2205642 to your computer and use it in GitHub Desktop.
Save dph01/2205642 to your computer and use it in GitHub Desktop.
class StatelessTestRV extends Logger {
object searchResults extends RequestVar[List[String]](Nil)
def doSearch(param: String) = {
// dummy results ....
"one" :: "two" :: "three" :: Nil
}
def processSubmit(param: String) = {
searchResults(doSearch(param))
var res = searchResults.is
S.seeOther("/stateless/results",() => searchResults(res))
}
def search = {
"*" #> S.request.map( r => {
if ( r.post_? )
// for post's, do search and redirect to results
r.param("queryparam").map( processSubmit(_) )
// if request is a post and r.param is set, processing will not get past here
// due to processSubmit calling a S.seeOther
// otherwise, just return the contents of the input nodeseq
(n: NodeSeq ) => n
}).openOr( (n: NodeSeq ) => n )
}
def results = {
".row *" #> searchResults.is.map( r => {
".value *" #> Text(r)
})}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment