problem getting started with css selectors

141 views
Skip to first unread message

ivan

unread,
Nov 23, 2010, 9:27:32 AM11/23/10
to Lift
Hi!

I am (for the second time) starting to play with lift (updated to the
newest version). I like the idea of binding with css selectors but I
have a problem figuring out how to do the folowing.

I have this snippet and template:

def list(in: NodeSeq) =
User.findAll.flatMap( user =>bind("user", in, "firstname" ->
user.firstName, "lastname" -> user.lastName) )

<table>
<lift:users.list>
<tr>
<td>
<user:firstname/>
</td>
<td>
<user:lastname/>
</td>
</tr>
</lift:users.list>
</table>

Now I want to change template to the folowing and utilize css
selectors but I have had no luck figuring it out so far. Can anyone
help please?

<table>
<tr class="lift:users">
<td>
<span class="firstname" />
</td>
<td>
<span class="lastname" />
</td>
</tr>
</table>

Thanks!

David Pollak

unread,
Nov 23, 2010, 9:33:56 AM11/23/10
to lif...@googlegroups.com
On Tue, Nov 23, 2010 at 6:27 AM, ivan <ivan....@gmail.com> wrote:
Hi!

I am (for the second time) starting to play with lift (updated to the
newest version). I like the idea of binding with css selectors but I
have a problem figuring out how to do the folowing.

I have this snippet and template:

def list(in: NodeSeq) =
       User.findAll.flatMap( user =>bind("user", in, "firstname" ->
user.firstName, "lastname" -> user.lastName)  )

<table>
       <lift:users.list>
               <tr>
                       <td>
                               <user:firstname/>
                       </td>
                       <td>
                               <user:lastname/>
                       </td>
               </tr>
       </lift:users.list>
</table>

Now I want to change template to the folowing and utilize css
selectors but I have had no luck figuring it out so far. Can anyone
help please?

Try:
def render(in: NodeSeq): NodeSeq = User.findAll.flatMap {
  u => ".firstname" #> user.firstName & ".lastname" #> user.lastName
}

 

<table>
       <tr class="lift:users">
               <td>
                       <span class="firstname" />
               </td>
               <td>
                       <span class="lastname" />
               </td>
       </tr>
</table>

Thanks!

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics

ivan

unread,
Nov 23, 2010, 10:08:17 AM11/23/10
to Lift
> Try:
> def render(in: NodeSeq): NodeSeq = User.findAll.flatMap {
>   u => ".firstname" #> user.firstName & ".lastname" #> user.lastName }

That looks simpler than any version I tried :D, but I now get this
compiler error:

[error] D:\ivans\Projects\Scala\lift\lift2tests\lift2test\src\main
\scala\code\snippet\Users.scala:35: type mismatch;
[error] found : net.liftweb.util.CssBindFunc
[error] required: Traversable[?]
[error] user => ".firstname" #> user.firstName & ".lastname" #>
user.lastName

Graham Tackley

unread,
Nov 23, 2010, 10:06:01 AM11/23/10
to Lift
>
> Try:
> def render(in: NodeSeq): NodeSeq = User.findAll.flatMap {
>   u => ".firstname" #> user.firstName & ".lastname" #> user.lastName

I think you copy and pasted too much ;) it needs to be:

def render = User.findAll.flatMap {
user => ".firstname" #> user.firstName & ".lastname" #>
user.lastName
}

since the css selectors return a CssBind object rather than a NodeSeq

Graham Tackley

unread,
Nov 23, 2010, 10:10:12 AM11/23/10
to Lift
try changing the flatMap to just a map

ivan

unread,
Nov 23, 2010, 10:42:39 AM11/23/10
to Lift
On 23 stu, 16:06, Graham Tackley <graham.tack...@guardian.co.uk>
wrote:
This is the code that I have. Error says found: CssBindFunc, required:
Traversable[?], I am not sure what is requiring a Traversable.

btw: thanks for responding so quickly. :)

ivan

unread,
Nov 23, 2010, 10:48:19 AM11/23/10
to Lift


On 23 stu, 16:10, Graham Tackley <graham.tack...@guardian.co.uk>
wrote:
> try changing the flatMap to just a map

Thanks!
That solved the compiler error :-), but now I have a problem in the
snippet:
Error processing snippet users.render.
Reason: Method Not Found
There are possible matching methods (render), but none has the
required signature:
def render(in: NodeSeq): NodeSeq

My template is:

<table>
<tr class="lift:users.render">

Graham Tackley

unread,
Nov 23, 2010, 11:19:45 AM11/23/10
to Lift
On Nov 23, 3:48 pm, ivan <ivan.se...@gmail.com> wrote:
> On 23 stu, 16:10, Graham Tackley <graham.tack...@guardian.co.uk>
> wrote:
>
> > try changing the flatMap to just a map
>
> Thanks!
> That solved the compiler error :-), but now I have a problem in the
> snippet:
> Error processing snippet users.render.
> Reason: Method Not Found
> There are possible matching methods (render), but none has the
> required signature:
> def render(in: NodeSeq): NodeSeq
>

Hmm that error message is not saying quite the right thing about the
required signature - looking at the code in LiftSession a signature of
(NodeSeq) => NodeSeq is one of a few that are acceptable. But the
gist is correct, it can't call your method.

render is the default method name that is invoked on a snippet, so
perhaps that is confusing things. Try changing your template to <tr
class="lift:users"> and see if that works.

Failing that, what version of lift are you using and can you post your
full snippet code?


ivan

unread,
Nov 23, 2010, 11:37:16 AM11/23/10
to Lift
On 23 stu, 17:19, Graham Tackley <graham.tack...@guardian.co.uk>
wrote:
I tried the above (<tr class="lift:users">), i am using lift 2.2-M1.

This is the entire error displayed in the browser:

Error processing snippet users.
Reason: Method Not Found
There are possible matching methods (render), but none has the
required signature:
def render(in: NodeSeq): NodeSeq
XML causing this error:
<tr xmlns="http://www.w3.org/1999/xhtml">
<td>
<span class="firstname"></span>
</td>
<td>
<span class="lastname"></span>
</td>
</tr>

David Pollak

unread,
Nov 23, 2010, 12:15:25 PM11/23/10
to lif...@googlegroups.com
On Tue, Nov 23, 2010 at 8:37 AM, ivan <ivan....@gmail.com> wrote:
On 23 stu, 17:19, Graham Tackley <graham.tack...@guardian.co.uk>
wrote:
> On Nov 23, 3:48 pm, ivan <ivan.se...@gmail.com> wrote:
> Hmm that error message is not saying quite the right thing about the
> required signature - looking at the code in LiftSession a signature of
> (NodeSeq) => NodeSeq is one of a few that are acceptable.  But the
> gist is correct, it can't call your method.
>
> render is the default method name that is invoked on a snippet, so
> perhaps that is confusing things.  Try changing your template to <tr
> class="lift:users"> and see if that works.
>
> Failing that, what version of lift are you using and can you post your
> full snippet code?

I tried the above (<tr class="lift:users">), i am using lift 2.2-M1.

This is the entire error displayed in the browser:

Please post a reproducible example (something that we can run with either Maven or sbt).
 

Error processing snippet users.
Reason: Method Not Found
There are possible matching methods (render), but none has the
required signature:
def render(in: NodeSeq): NodeSeq
XML causing this error:
<tr xmlns="http://www.w3.org/1999/xhtml">
               <td>
                   <span class="firstname"></span>
               </td>
               <td>
                   <span class="lastname"></span>
               </td>
           </tr>
--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.

Mads Hartmann Jensen

unread,
Nov 23, 2010, 1:48:56 PM11/23/10
to lif...@googlegroups.com
I was able to get it to work like this. 

----- Users.scala -----
package com.sidewayscoding.snippet

import net.liftweb.common._
import net.liftweb.http.{ S }
import net.liftweb.http.S._
import net.liftweb.http.SHtml._
import net.liftweb.util._
import Helpers._
import net.liftweb.util.Helpers._

class Users {

  val users = ("Mads", "Hartmann") :: ("Eva", "Regnar") :: Nil

  def render = {
    "#lines *" #> users.map {
      case (firstname, lastname) =>
        ".firstname" #> firstname &
          ".lastname" #> lastname
    }
  }

}
----- Users.scala ends here -----

----- Template file -----
<table class="lift:Users.render">
<tr id="lines">
   <td>
       <span class="firstname"/>
   </td>
   <td>
       <span class="lastname"/>
   </td>
</tr>
 </table>
----- Template file ends here -----

ivan

unread,
Nov 23, 2010, 2:16:29 PM11/23/10
to Lift
Thanks! It works!! :)
This is really one of the best and most responsive communities ever :)

Mads Hartmann Jensen

unread,
Nov 23, 2010, 2:33:08 PM11/23/10
to lif...@googlegroups.com
Happy I could help - Good luck with your Lift-adventure :)

- Mads

Reply all
Reply to author
Forward
0 new messages