Newbie Help: Displaying a list

4 views
Skip to first unread message

Dominic Preuss

unread,
Jul 5, 2010, 5:56:47 PM7/5/10
to lif...@googlegroups.com
Everyone,

A quick question from a newbie with Java experience.  I find it odd that there isn't a simple tutorial (not using ajax/comet) using Lift 2.0 the returns a List and binds it to a table/ul.

I am trying to get a list of items to display, but get an error that I can't figure out.  I have object in the database that get returned from Item.findAll.

Item.scala

class Item extends LongKeyedMapper[Item] with IdPK {
def getSingleton = Item
object upc_code extends MappedInt (this)
object name extends MappedPoliteString(this, 128)
object desc extends MappedPoliteString(this, 512)
object lat extends MappedLong(this)
object long extends MappedLong(this)
object owner extends MappedLongForeignKey (this, User)
}

object Item extends Item with LongKeyedMetaMapper[Item] 

Snippet:

    def list(html: NodeSeq) = { 
    
     var allItems : List[Item] = Item.findAll()
    
     allItems.flatMap(item => bind("item", html, "name" -> item.name) )
    
}

Template:

<div>
<ul>
<lift:TD.list>
<li>Name: <item:name /> </li>
</lift:TD.list>
</ul>
</div>
The error is:

error on line 82 at column 26: Namespace prefix item on name is not defined

I can change the binding to return a simple string, but returning dynamic values creates this error.

Thoughts?

ghostM

unread,
Jul 5, 2010, 8:01:19 PM7/5/10
to Lift
I ran into this the other day and here is an example of what I did
(there might be a better way since I'm still new to Lift)

In index.html

<lift:surround with="default" at="content">
<h2>Welcome to your project!</h2>
<p>
<lift:helloWorld.showList>
<ul>
<hwList:list>
<li>
<hwl:listItem/>
</li>
</hwList:list>
</ul>
</lift:helloWorld.showList>
</p>
</lift:surround>

And then in your HelloWorld snippet:

def showList (html: NodeSeq) : NodeSeq = {
val listToShow = (1 to randomInt(10)).map(i => i)
def processClick(){
}
bind("hwList", html,
"list" -> listToShow.flatMap(num =>
bind("hwl", chooseTemplate("hwList", "list", html),
"listItem" -> SHtml.link("/"+num, processClick,
Text(num.toString) ))))
}

(I tested it out using the lift_sbt_prototype and all I needed to add
was an import net.liftweb.http.SHtml )

Hope this helps

Mads Hartmann Jensen

unread,
Jul 6, 2010, 3:16:49 AM7/6/10
to lif...@googlegroups.com
Hey Dominic,

If you need some explanations and examples of bindings see the lift wiki: https://www.assembla.com/wiki/show/liftweb/Templates_and_Binding

This part explains how to properly bind the content of a list:
https://www.assembla.com/wiki/show/liftweb/Templates_and_Binding#a_bit_more_advanced_example

> --
> 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.
>

David Pollak

unread,
Jul 6, 2010, 8:05:23 PM7/6/10
to lif...@googlegroups.com

You're using Lift 1.0.  If you were using Lift 2.0, you would get a friendly error message indicating that the TD snippet wasn't found.
 

--
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

Dominic Preuss

unread,
Jul 7, 2010, 3:28:30 PM7/7/10
to Lift
David,

I built this using -Dversion=2.0-SNAPSHOT and my pom.xml verifies this
(below). Is there a way to force an update to the 2.0 Release?

==
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>smartsy</groupId>
<artifactId>smartsy</artifactId>
<version>2.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>smartsy</name>
<inceptionYear>2007</inceptionYear>
<properties>
<scanIntervalSeconds>0</scanIntervalSeconds>
<scala.version>2.7.3</scala.version>
</properties>



<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>

==

Is there an easy way to update my project?

Dominic


On Jul 6, 8:05 pm, David Pollak <feeder.of.the.be...@gmail.com> wrote:
> > liftweb+u...@googlegroups.com<liftweb%2Bunsu...@googlegroups.com >
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/liftweb?hl=en.
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890

Dominic Preuss

unread,
Jul 7, 2010, 3:32:59 PM7/7/10
to Lift
Apologies, I just realized my repo URL was wrong (should have been
http://scala-tools.org/repo-snapshots), so I wasn't getting updates.


On Jul 7, 3:28 pm, Dominic Preuss <domi...@dominicpreuss.com> wrote:
> David,
>
> I built this using -Dversion=2.0-SNAPSHOT and my pom.xml verifies this
> (below).  Is there a way to force an update to the 2.0 Release?
>
> ==
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd">
Reply all
Reply to author
Forward
0 new messages