On 2010-04-03 23:28, John Bender wrote:
Simon,
While I don't have any hands on experience with Lift's approach to templating it looks a lot like asp.net databinding/templates and from my experience with that toolset it ends up being a cumbersome solution to the problem of separating controller and view. I don't necessarily think mixing code into your views is the "one true way" either, but what you sacrifice in controller code clarity seems to outweigh any gains from separating the two so strictly.
As an example from http://liftweb.net/docs/getting_started/mod_master.html#x1-130002.7 :
<lift:TD.list all_id="all_todos"> <div id="all_todos"> <div>Exclude done<todo:exclude/></div> <ul> <todo:list> <li> <todo:check><input type="checkbox"/></todo:check> <todo:priority> <select><option>1</option></select> </todo:priority> <todo:desc>To Do</todo:desc> </li> </todo:list> </ul> </div> </lift:TD.list>
private def doList(reDraw: () => JsCmd)(html: NodeSeq): NodeSeq = toShow. flatMap(td => bind("todo", html, "check" -> ajaxCheckbox(td.done, v => {td.done(v).save; reDraw()}), "priority" -> ajaxSelect(ToDo.priorityList, Full(td.priority.toString), v => {td.priority(v.toInt).save; reDraw()}), "desc" -> desc(td, reDraw) ))
In the above you'll notice that the bind has direct reference to elements in the template, so I think its fair to say you've moved some of your template mixing from view to the controller. From the docs
Disclaimer: I've only done a very simple (and incomplete) application in Liftweb. YMMV. Anyway, regardless of what you do there has to be _some_ connection between the view and the controller (backend) and in my experience, the "View first" approach of Liftweb does a very good job here. A major advantage is that the view is 100% pure XHTML/HTML so that it can be edited in any XML editor. It also contains placeholder data so that most of the layout/design can be done independently of having the actual application running. (That's the theory, anyway. I haven't done this on any sort of large scale, so again YMMV.) The only approach I can think of which would do away with having a binding mechanism would be to generate all the front end HTML/XHTML/JS completely from Haskell. This is great for developers, but not so good for the "web designer" crowd. Cheers,