In the short term you would solve it as I suggested:

Use in your bind

 "searchBox" -%> doSearch

and define your doSearch as:

def doSearch: NodeSeq =  {
... do your stuff here
}

Actually thinking more into it there is a good reason for -%> to not
have a (NodeSeq) => NodeSeq support. -%> means that it preserves the
attributes specified in the template to the resulting node.But having
a bunch of attributes we can't apply them to a NodeSeq because aa
NodeSeq means a sequence of Nodes with no commn parent so we can;t
determine to which node we'd apply those attributes. AFAIK only an
Elem can have attributes.




On Mar 6, 6:45 pm, Luke  Nezda <lne...@gmail.com> wrote:
> Thanks for responding Marius.  You're right, my doSearch method
> doesn't need the msg parameter -- that was just an artifact of
> transforming an example (removed now).  As far as my specific issue, I
> guess you're saying the best solution is for the framework to add
> overload def -%>(in: NodeSeq => NodeSeq) congruent with -> -- should I
> file a feature request?  As you said, Group(FocusOnLoad...) doesn't
> compile either because it returns a Node, not the currently required
> Element.  Did I misunderstand?  

You are correct. I mainly pointed to Group just as a reminder as it
can be useful to "aggregate" nodes. It wont work in your case.

In the short term how would you solve
> this ?
>
> Thanks,
> - Luke
>
> On Mar 6, 1:39 am, Marius <marius.dan...@gmail.com> wrote:
>
>
>
> > 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.

Reply via email to