I have been working on Scala and Lift for a few weeks now and wanted
to post some of my code samples here and hopefully they are useful to someone
else in the future.
I would like to first say thank you to all those involved with developing and
creating the liftweb demos. I know doing that can be a huge PITA, so
Thanks! I would simply like to ask that future versions of demo code include
the html file code that produces the UI output. Having only the backend code
causes a bit of stumbling.
The first examle I worked on was based on the Ajax
(http://demo.liftweb.net/ajax) sample from liftweb. Here is the code
below.
File: ajax.html
123456789
<lift:surroundwith="default"at="content"><div><lift:AjaxSample.sample><ajax:clicker>Click here to update count <spanid="cnt_id">0</span></ajax:clicker><br/><ajax:autolimit="20"/></lift:AjaxSample.sample>
</div></lift:surround>
importnet.liftweb.http._importjs.jquery.JqJsCmds.DisplayMessageimportjs.JsCmds.SetHtmlimportS._importSHtml._importnet.liftweb.util._importHelpers._importscala.xml._importnet.liftweb.http.js._importnet.liftweb.common.{Empty,Logger,Full}importjava.lang.Stringimportnet.liftweb.widgets.autocomplete.AutoCompleteclassAjaxSample{defsample(xhtml:NodeSeq):NodeSeq={// local state for the countervarcnt=0// get the id of some elements to updatevalspanName:String=S.attr("id_name")openOr"cnt_id"valmsgName:String=S.attr("id_msgs")openOr"messages"// build up an ajax <a> tag to increment the counterdefdoClicker(text:NodeSeq)=a(()=>{cnt=cnt+1;SetHtml(spanName,Text(cnt.toString))},text)// bind the view to the functionalitybind("ajax",xhtml,"clicker"->doClicker_,"auto"->AutoComplete("",buildQuery_,_=>()))}privatedefbuildQuery(current:String,limit:Int):Seq[String]={Log.info("Checking on server side with "+current+" limit "+limit)(1tolimit).map(n=>current+""+n)}}
All that this example does is simply do the a href tag ajax click to increment
the number and builds a autocomplete box that will simply show 10 of whatever
text you are typing retrieved via ajax of course.
I will keep putting my code samples up here as I create them.