On 22 feb., 04:12, Luke Nezda <lne...@gmail.com> wrote: > Hello, > > I am new to Scala and Lift. I am having a problem using 2 features > together which seem to work fine individually. Here's a simplified > piece of the code: > > class Ajax { > def someResult(q:String) = <span>some results for query {q}...</ > span> > // searchField closure > def searchField(xhtml: NodeSeq): NodeSeq = { > // build up an ajax text box > def doSearch(msg: NodeSeq) = { > // doesn't compile with bind: "searchBox" -%> doSearch _ > FocusOnLoad(SHtml.ajaxText("", q => SetHtml("resultz", > someResult(q)))) > // compiles with bind: "searchBox" -%> doSearch _ > // SHtml.ajaxText("", q => SetHtml("resultz", someResult(q))) > } > // bind the view to the functionality > bind("ajax", xhtml, > "searchBox" -> doSearch _ > // doesn't compile if doSearch returns result of FocusOnLoad > //"searchBox" -%> doSearch _ > ) > } > > } > > and the template invocation: > > <lift:surround with="default" at="content"> > <lift:Ajax.searchField id_msgs="messages"> > <ajax:searchBox class="text" type="search" tabindex="1" /> > <hr class="space"/> > <div id="resultz"></div> > <div id="messages"></div> > </lift:Ajax.searchField> > </lift:surround> > > My goal is an Ajax-enabled text input that gets focus when the page > loads and has various attributes of the input element set. I realize > I can use the SHtml.ajaxText variant that takes attribute-value pairs, > as in: > > FocusOnLoad(SHtml.ajaxText("", q => SetHtml("resultz", > Yawni.query(q)), ("class", "text"), ("type", "search"), ("tabindex", > "1"))) > > but I'm trying to keep the various element attributes in the template. > > When I try to bind with: > "searchBox" -%> doSearch _ > instead of: > "searchBox" -> doSearch _ > > I get the following compile error: > > snippet/Ajax.scala:109: error: overloaded method value -%> with > alternatives ((scala.xml.NodeSeq) => > scala.xml.Elem)net.liftweb.util.Helpers.FuncBindParam <and> > (Option[scala.xml.Elem])net.liftweb.util.Helpers.FuncBindParam <and> > (net.liftweb.common.Box[scala.xml.Elem])net.liftweb.util.Helpers.FuncBindPa > ram > <and> (scala.xml.Elem)net.liftweb.util.Helpers.FuncBindParam cannot be > applied to ((scala.xml.NodeSeq) => scala.xml.NodeSeq) > "searchBox" -%> doSearch _ > ^ > one error found
Why your doSearch function takes a msg parameter? ... it doesn't seam to use it. doSearch _ is a partially applied function and acts as a (NodeSeq) => NodeSeq however -%> has only a definition like: def -%>(in: NodeSeq => Elem) while -> also has def ->(in: NodeSeq => NodeSeq) which is why you get the compile error. We should add the same definition for NodeSeq => NodeSeq You can simply say: "searchBox" -%> doSearch and have def doSearch: NodeSeq = ... FocusOnLoad returns a NodeSeq because it returns a sequence of nodes which conceptually cannot be converted to an elem. You could try to have a Group(FocusOnLoad ...) ... but Group is a Node not an Elem. > > Between all the bind() and ->()/-%>() overloads and my general Scala / > Lift ignorance, I can't understand what the right way to resolve this > is. I think it has something to do with FocusOnLoad returning a > NodeSeq (<input/><script/>) vs. an Element, but I don't know where to > go from here... > > Thanks in advance, > - Luke -- 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.