New to: lift

21 views
Skip to first unread message

coughlinsmyalias

unread,
Apr 7, 2008, 12:02:39 PM4/7/08
to liftweb
Hey,

I am new to lift and just started doing some research on it. I am
using jQuery to program:

http://rksdesignstudios.com/magnet/

I am trying to keep it as live/updated as possible, would lift work
for me?

And if I am an avid PHP/jQuery user, what kind of transition will it
be to lift?

Is it similar to Ruby on Rails, I was guessing by the structure while
doing my research.

Looking at some code examples and kind of confused about lift.

Thanks for your help!

Ryan

David Pollak

unread,
Apr 7, 2008, 1:11:14 PM4/7/08
to lif...@googlegroups.com
Ryan,

lift has these nifty things called CometActors.  As the name suggests, they are chunks of code to do comet.

In your view (lift has a view-first architecture see http://liftweb.net/index.php/Lift_View_First), you'd do something like:

<lift:comet type="MagnetBoard" />

Then you'd create a class that looks like:

class MagnetBoard(initInfo: CometActorInitInfo) extends CometActor(initInfo) {
   def defaultPrefix = "board"

   private var stuckOnMe: List[Magnet] = Nil

   def render = <div class="magnet_board">{stuckOnMe.map(_.renderAMagnet)}</div>

   def lowPriority = {
     case AddMagnet(magnet) => stuckOnMe = magnet :: stuckOnMe ; reRender(false)

     case RemoveMagnet(magnet) => stuckOnMe = stuckOnMe.remove(_.id == magnet.id); reRender(false)

     case UpdateMagnet(magnet) => stuckOnMe = magnet :: stuckOnMe.remove(_.id == magnet.id); reRender(false)
   }

}

case class AddMagnet(magnet: Magnet)
case class RemoveMagnet(magnet: Magnet)
case class UpdateMagnet(magnet: Magnet)

class Magnet(val id: String, val message: String, val xpos: Int, val ypos: Int) {
  def renderAMagnet = <div id={id} class="magnet" style={"top: "+ypos+"; left: "+xpos}>{message}</div>
}
Is this your whole app?  Except for the part that updates the Magnets, yes.

Do you have to do anything fancy to get lift to do all the Comet stuff?  No.  It's automatically taken care of when you put a CometActor into a view.

Thanks,

David

Tim Perrett

unread,
Apr 7, 2008, 1:12:40 PM4/7/08
to liftweb
> And if I am an avid PHP/jQuery user, what kind of transition will it
> be to lift?

To be brutally honest - I have quite a lot of Java experience I have
struggled getting to grips with Scala at first. It is somewhat mind
bendingly different. If you have no JEE experience even things like
deployment will become a seriously steep learning curve for you. I
wouldn't want to dissuade you from learning /lift/, rather, just go
into it with your eyes open and accept that it is extremely likely
that things will be very tough to understand for quite some time.

> Is it similar to Ruby on Rails, I was guessing by the structure while
> doing my research.

Strictly speaking, no its not. /lift/ is a view first framework where
as Rails uses a front controller pattern which is dispatched to the
right controller based on the URI. The paradigms are really very
different. Even the way that development works with maven is different
- im by no means an expert regarding /lift/ but having done work in a
whole bunch of different languages (including PHP back in the day) I
can say that it is a million million light-years away from PHP!

> I am trying to keep it as live/updated as possible, would lift work
> for me?

Granted, /lift/ has awesome comet support, but comet is a design
pattern rather than something exclusive /lift/ - perhaps if you are
working in PHP you could check out http://ajaxian.com/archives/comet-with-php

Hope that helps

Tim

David Pollak

unread,
Apr 7, 2008, 1:30:09 PM4/7/08
to lif...@googlegroups.com
Tim,

Thanks for sharing your perspective.  After drinking 18 months worth of Scala cool-aid, it's really helpful and valuable to hear the perspectives (and challenges) other face when learning lift and Scala.

Thanks!

David

coughlinsmyalias

unread,
Apr 7, 2008, 2:52:54 PM4/7/08
to liftweb
Thank you for all of this! I guess it will be a fun learning
experience, haha. I think this is the way that I want to go, to get my
app to do what I want it to do. Can lift run on any web server? As in
apache, i am being hosted with GoDaddy.

Thank you both!

Ryan
> working in PHP you could check outhttp://ajaxian.com/archives/comet-with-php
>
> Hope that helps
>
> Tim

Tim Perrett

unread,
Apr 7, 2008, 4:01:55 PM4/7/08
to liftweb
Hey coughlinsmyalias,

This is exactly what I was refering to in my previous post - if you
are not familiar with JEE then /lift/ could quite possibly not be for
you. To run /lift/ you need to compile a WAR file using maven which in
turn compiles the scala code with the scala compiler. As you can see,
this is not PHP, you can not just upload files to the server and
expect it to work. You have to write code, then test code, compile WAR
and deploy to your favorite JEE container (e.g Tomcat, Jetty, Resin
etc etc)

I cant speak for all the /lifters/, but id have a guess that the vast
majority of us have our own deployment servers that run in a dedicated
setup (co-lo etc) - typicaly, JVM applications eat shed loads of RAM
(compared to PHP processes) so either need expensive hosting, or
dedicated equipment.

Does that make sense?

Thanks

Tim

TylerWeir

unread,
Apr 7, 2008, 4:30:42 PM4/7/08
to liftweb
I took Dave's code and turned it into a working example, minus a form
to add words.

I'll post it to github.com later tonight.

If you want the code email me, otherwise it should be up by 10:00pm
EST.

TylerWeir

unread,
Apr 7, 2008, 4:38:56 PM4/7/08
to liftweb

coughlinsmyalias

unread,
Apr 7, 2008, 5:29:22 PM4/7/08
to liftweb
I see now, this makes more sense. Thank you for all of this, do you
recommend one JEE over another? I am on a Mac if it matters at all.

I will check out some docs and tutorials on this, I really do
appreciate all of your help!

Thanks,

Ryan

coughlinsmyalias

unread,
Apr 7, 2008, 5:31:47 PM4/7/08
to liftweb
Thank you so much! I really appreciate this, this will be a huge help
to see it in action and take a look at the code.

Thank you Tyler. I will check back around then or post a quick message
here. With lift, I am able to use all jQuery effects, correct, like I
have on my current app?

Ryan

On Apr 7, 4:30 pm, TylerWeir <tyler.w...@gmail.com> wrote:

coughlinsmyalias

unread,
Apr 7, 2008, 5:47:25 PM4/7/08
to liftweb
Thank you both! That does make much more sense now, which JEE would
you recommend, are there big main differences? I am on a Mac. or does
it not matter since its Java.

Tyler, thanks so much! I am glad I can see it in action, I will be
able to see the source as well? Or since it uses compliers?

Ryan

coughlinsmyalias

unread,
Apr 7, 2008, 5:51:46 PM4/7/08
to liftweb
********

Sorry for the double reply :p

Tim Perrett

unread,
Apr 7, 2008, 6:10:07 PM4/7/08
to liftweb

> Thank you both! That does make much more sense now, which JEE would
> you recommend, are there big main differences?

Check out this thread - http://groups.google.com/group/liftweb/browse_thread/thread/520b6e9215ea6dbe

Everyone is doing something different; its pretty non-prescriptive to
be honest. A lot of it comes down to what you know and/or personal
preference. I've just started deploying onto Caucho Resin and thats
working fine as well.

coughlinsmyalias

unread,
Apr 7, 2008, 6:32:23 PM4/7/08
to liftweb
Thanks Tim! Ill go check out this article.

Ryan

On Apr 7, 6:10 pm, Tim Perrett <he...@timperrett.com> wrote:
> > Thank you both! That does make much more sense now, which JEE would
> > you recommend, are there big main differences?
>
> Check out this thread -http://groups.google.com/group/liftweb/browse_thread/thread/520b6e921...

coughlinsmyalias

unread,
Apr 7, 2008, 6:33:54 PM4/7/08
to liftweb
That thread is perfect for that topic. Haha

On Apr 7, 6:10 pm, Tim Perrett <he...@timperrett.com> wrote:
> > Thank you both! That does make much more sense now, which JEE would
> > you recommend, are there big main differences?
>
> Check out this thread -http://groups.google.com/group/liftweb/browse_thread/thread/520b6e921...

TylerWeir

unread,
Apr 7, 2008, 8:38:16 PM4/7/08
to liftweb
Hey dudes.

Check it out. Haha.. puns are great.

http://github.com/tjweir/liftweb-fridgemagnets/

I also have 2 github account invites, if anyone is interested.

Ty

On Apr 7, 4:30 pm, TylerWeir <tyler.w...@gmail.com> wrote:

coughlinsmyalias

unread,
Apr 7, 2008, 11:24:42 PM4/7/08
to liftweb
Thank you! Big thing though...how do I preview it? Haha

THanks for all of this.

TylerWeir

unread,
Apr 8, 2008, 8:03:52 AM4/8/08
to liftweb
Oh , download the archive.

cd to"magnetboard"

then "mvn install jetty:run"

This assumes you have java, scala and maven2 installed.

Ty

David Bernard

unread,
Apr 8, 2008, 4:27:34 PM4/8/08
to lif...@googlegroups.com
"mvn jetty:run" is enough

calling "mvn install" is overkill for webapp/war

coughlinsmyalias

unread,
Apr 8, 2008, 4:55:08 PM4/8/08
to liftweb
Thank you both, I am having some trouble installing Maven though, any
suggestions? I am on Mac OS X

TylerWeir

unread,
Apr 8, 2008, 5:06:17 PM4/8/08
to liftweb
I just followed the instructions on the bottom of this page:
http://maven.apache.org/download.html

What trouble are you having?

coughlinsmyalias

unread,
Apr 8, 2008, 5:14:21 PM4/8/08
to liftweb
When it says:

# In a command terminal, add the M2_HOME environment variable, e.g.
"export M2_HOME=/usr/local/apache-maven/apache-maven-2.0.8" .

What does that mean? I know the command terminal, etc, but not sure
what that means, and do I have to place it in the dir? usr/local? And
as well as the step above, are the others the same as above?

Thanks,

Ryan

David Bernard

unread,
Apr 8, 2008, 5:25:50 PM4/8/08
to lif...@googlegroups.com
1. you have to unarchive the download archive eg: /usr/local or /opt where you want
2. create the environment variable M2_HOME that point to the directory where is maven (if you unarchive into /usr/local then M2_HOME is /usr/local/apache-maven-2.0.8)
3. add to your PATH environment variable $M2_HOME/bin

the 2. and 3. step is only to allow you to call maven "mvn ..." without using the fullpath (eg: "/usr/local/apache-maven-2.0.8/bin/mvn")

is it clear ?

/davidB

coughlinsmyalias

unread,
Apr 8, 2008, 9:10:39 PM4/8/08
to liftweb
I got it :) My answer is in the other post and I supplied the link to
what fixed it as well, the article just came out too, in March.

I am working on viewing the app you guys put together for me! I'll let
you know how it goes.

coughlinsmyalias

unread,
Apr 8, 2008, 9:20:31 PM4/8/08
to liftweb
After I do this and it installs jetty, scala and all those other
packages, how do I preview it in the browser?

Ryan

coughlinsmyalias

unread,
Apr 8, 2008, 9:23:06 PM4/8/08
to liftweb
I got it, I went to localhost:8080/

On Apr 8, 8:03 am, TylerWeir <tyler.w...@gmail.com> wrote:

coughlinsmyalias

unread,
Apr 8, 2008, 9:30:27 PM4/8/08
to liftweb
Tyler after messing around with this I have a couple of questions:

1. Right now, the words are static and not being drawn from a
database?

2. Say I want to start to incorporate what you did with my styles at:
http://rksdesignstudios.com/magnet/ - I do this with the source code
correct? Just change up DIV, etc According to how i want them.

3. To connect to my database here on my localhost/ what do i need to
do, for i can draw ALL of my words and make them in:

<span class="word">dog</span>

So they all load like that.

4. The code like:

<script>
// <![CDATA[
var lift_toWatch = {LCQJ2ZEK441B5BIIJMAZ4M: '2'};
function lift_handlerSuccessFunc()
{setTimeout("lift_cometEntry();",100);}
function lift_handlerFailureFunc()
{setTimeout("lift_cometEntry();",10000);}
function lift_cometEntry() {jQuery.ajax( {url: '/
comet_request', cache: false, success: lift_handlerSuccessFunc,
timeout: 140000, data: lift_toWatch, dataType: 'script', error:
lift_handlerFailureFunc} );}
jQuery(document).ready(function()
{lift_handlerSuccessFunc();});
// ]]>
</script>

Is generated via lift correct? The cometActor takes care of this?

5. If I wanted to add in a form, and have it submit via ajax/comet,
then publish my word on the page like the others how would I go about
that. I am going to go play with some of the tutorials that are
located on the lifted site.

Sorry for all of the bombardment, just trying to understand this, I
love this framework so far :)

Thanks everyone for your support. I really appreciate it.

On Apr 8, 8:03 am, TylerWeir <tyler.w...@gmail.com> wrote:

TylerWeir

unread,
Apr 8, 2008, 10:17:24 PM4/8/08
to liftweb
1. Yup, just hard coded. I only spent a couple minutes on this. :)
2. Look at style.css in the /webapp/ directory. You can define all
the styles there.
3. Take a look at the liftweb wiki, there are entries that will help
connecting to databases.
4. Yes, that's /lift/ generated.
5. That's on the list of to-dos for me. Flipping through the
tutorials, you'll find out how to do this.

Tyler

coughlinsmyalias

unread,
Apr 9, 2008, 12:48:26 AM4/9/08
to liftweb
Thank you Tyler. I will go ahead and keep playing and find out how to
connect up to my database.

coughlinsmyalias

unread,
Apr 9, 2008, 10:07:41 PM4/9/08
to liftweb
Tyler,

I am having trouble finding where you specified the words to be
displayed on the mag app when you load it? Where can I find those?

Thanks,

Ryan

On Apr 8, 10:17 pm, TylerWeir <tyler.w...@gmail.com> wrote:

coughlinsmyalias

unread,
Apr 9, 2008, 10:44:49 PM4/9/08
to liftweb
Hey Dave and others,

I spent the night on and off understanding the lift structure and
taking tutorials, I am starting to understand how it works and what
makes it works, I really love this framework so far :) I am very
pleased on top of all the help I am getting, I do appreciate it!

I added in some styling to the code you guys supplied me and it can be
found here: http://rksdesignstudios.com/files/magnetboard.zip

The next things on my to do list are to:

1. Add in the form at the top right using lift.
- on submit add the word via mysql database and print on page
like others
- add in callbacks so on page add do this jquery effect
2. Create a repositioning effect
- save x/y positions to database and retreive for ALL elements
- doing this so on page refresh they will remain in the same
place
2a. Once reposition is working
- be able to have page push content (comet) to the page,
to keep it updated.
3. Work in delete method.

I am going to start with working on the MySQl database using the
tutorial on the lift site. That is the first thing I should start.

I have a feeling its going to be a tough one, haha. Tim or Dave, I
might have some questions about understanding the code that you
supplied for me, what is the best way for me to do that? Post a new
one or continue here, I want to keep things organized for you guys and
for others who are wondering about LIFT!

Thanks everyone for the help,

Ryan

On Apr 7, 1:11 pm, David Pollak <d...@athena.com> wrote:
> Ryan,
> lift has these nifty things called CometActors.  As the name suggests, they are chunks of code to do comet.
> In your view (lift has a view-first architecture seehttp://liftweb.net/index.php/Lift_View_First), you'd do something like:<lift:comet type="MagnetBoard" />
> Then you'd create a class that looks like:class MagnetBoard(initInfo: CometActorInitInfo) extends CometActor(initInfo) {   def defaultPrefix = "board"   private var stuckOnMe: List[Magnet] = Nil   def render = <div class="magnet_board">{stuckOnMe.map(_.renderAMagnet)}</div>
>    def lowPriority = {
>      case AddMagnet(magnet) => stuckOnMe = magnet :: stuckOnMe ; reRender(false)
>      case RemoveMagnet(magnet) => stuckOnMe = stuckOnMe.remove(_.id == magnet.id); reRender(false)
>      case UpdateMagnet(magnet) => stuckOnMe = magnet :: stuckOnMe.remove(_.id == magnet.id); reRender(false)
>    }}
> case class AddMagnet(magnet: Magnet)case class RemoveMagnet(magnet: Magnet)case class UpdateMagnet(magnet: Magnet)class Magnet(val id: String, val message: String, val xpos: Int, val ypos: Int) {
>   def renderAMagnet = <div id={id} class="magnet" style={"top: "+ypos+"; left: "+xpos}>{message}</div>
> }Is this your whole app?  Except for the part that updates the Magnets, yes.
> Do you have to do anything fancy to get lift to do all the Comet stuff?  No.  It's automatically taken care of when you put a CometActor into a view.
> Thanks,
> David
> coughlinsmyalias wrote:Hey, I am new to lift and just started doing some research on it. I am using jQuery to program:http://rksdesignstudios.com/magnet/I am trying to keep it as live/updated as possible, would lift work for me? And if I am an avid PHP/jQuery user, what kind of transition will it be to lift? Is it similar to Ruby on Rails, I was guessing by the structure while doing my research. Looking at some code examples and kind of confused about lift. Thanks for your help! Ryan

coughlinsmyalias

unread,
Apr 12, 2008, 10:07:11 AM4/12/08
to liftweb
David, when you run:

mvn install jetty:run

What is the difference compared to:

mvn jetty:run

Does the first one install updates? Make sure everything is up to
date, then proceeds to run the server.

Ryan

On Apr 8, 4:27 pm, David Bernard <david.bernard...@gmail.com> wrote:

Tim Perrett

unread,
Apr 12, 2008, 12:43:32 PM4/12/08
to liftweb
mvn install jetty:run installs the artifact into the local repository
then starts jetty, where as jetty:run as you can imagine, just runs
the jetty server.

Tim

coughlinsmyalias

unread,
Apr 13, 2008, 11:08:21 AM4/13/08
to liftweb
So it is not necessary to run that install everytime?

Thanks,

Ryan

David Bernard

unread,
Apr 13, 2008, 11:51:04 AM4/13/08
to lif...@googlegroups.com
Yes, it is not necessary to run install
IMO, you should never need to run "install" for webapp (except if it part of an ear,...).

see http://liftweb.net/index.php/Maven_Mini_Guide (I never call install)

/davidB

Reply all
Reply to author
Forward
0 new messages