views:

1553

answers:

2
+7  Q: 

MVC on Lift/Scala

Has anyone tried to do a scala/lift application using MVC instead of view-first?

I know that you can create Controllers/views as:

package test.test.test.view
...
Lots of imports
...
class MvcRocks extends LiftView {
  def dispatch = { 
    case "rule" => ruleDispatch _
    case "bar" => barDispatch _
  }
  def barDispatch(): Box[NodeSeq] = {
     Full(<lift:embed what="/mvc_rucks/bar" />)
  }
}

And this code will be accessible if you add it to the menu(in the boot), even if its hidden as:

val entries = Menu(Loc("Home", List("index"), "Home")) ::
List(Menu(Loc("MvcRock", List("mvc_rocks", "bar"), "Mvc really Rocks", Hidden)))
LiftRules.setSiteMap(SiteMap(entries:_*))

Now, of course this will make it so, you declare every action in the menu, then have a case for each action(per controller) and that would open the "view" (that would be a file in /mvc_rucks/bar.html).

My question is, if you would implement a full mvc, you would need to put all your logic in the action barDispatch, but how would you send those variables to the HTML template? and how would you receive post/get information?

(Notice that if you html code has lift bindings, it will of course act as view-first, even after you did MVC before).

+1  A: 

I'm new to Scala/Lift, so I can't answer your question, but am really interested in the answer if you find it.

I'm also interested in why we'd prefer MVC. It seems like David Pollock was pretty specific in designing Lift to be view-first because of the amount of separate logic on a page (as is described in Lift: View First). Is there a strong reason why MVC would be preferrable that I should be aware of, other than an ease of use for us coming from the MVC side?

JohnMetta
Well; because a view-first pattern allows you to have code anywhere and its pretty hard to manage that(you can see a glance of this trouble with the long, long, long menu declarations)
DFectuoso
This should be a comment.
James McMahon
+7  A: 

Since your question is not specific to Lift, I'd recommend you the Playframework. The version 1.1 supports Scala 2.8.

Playframework is totally MVC with a fantastic template engine and allows you to choose freely between java/scala.

And I say: To use Play, you don't need 'nuclear scientist knowledge'. Try it!

paulosuzart
"Finally a Java framework made by Web developers. Discover a clean alternative to bloated enterprise Java stacks." - the "Play!" main page says. I never knew such a thing exists and always dreamed of. Thanks a lot, Paulo.
Ivan
Some developers sometimes forget we want simplicity :) Play is one of the answers for that. I'm looking for something even simpler. Look for JTornado on Github. I'm really focused on that. Thanks!
paulosuzart