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.FuncBindParam
<and> (scala.xml.Elem)net.liftweb.util.Helpers.FuncBindParam cannot be
applied to ((scala.xml.NodeSeq) => scala.xml.NodeSeq)
"searchBox" -%> doSearch _
^
one error found
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en.