Hi - I'm about halfway through the new ToDo Tutorial available here:
http://groups.google.com/group/liftweb/browse_thread/thread/0d99974c622262d5# and I wanted to try adding a new column "loc" ("Location"). (NOTE: As pointed out in another threads here today, you have to do 'cd todo' before doing 'mvn jetty:run' on page 6 of the tutorial.) I added my new column "loc" ("Location") to the model, and it displays on the screen (in the list of existing ToDo's, and below in the form for adding a new ToDo), but I can't control the formatting - my columns aren't straight. (They just happened to be straight in the *basic* tutorial because the "desc" or "Description" happens to be the last column, and all the preceding columns are either Boolean or drop-down menu, which are fixed width.) Anybody have an example of this? Between the currying and the Ajax, I can't quite wrap my mind around how the html is being generated. Thanks. I'm very exciteds about Scala and /lift/ ! - Stefan Scott Here are the 3 files I've updated: C:\www\jetty\webapps\todo\src\main\webapp\ToDo.scala <lift:surround with="default" at="content"> <lift:Util.in> <lift:TD.list all_id="all_todos"> <div id="all_todos"> <div>Exclude done <todo:exclude/></div> <ul> <todo:list> <li> <todo:loc>Location</todo:loc> <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> <lift:TD.add form="post"> <table> <tr> <td>Location:</td> <td><todo:loc>Location</todo:loc></td> </tr> <tr> <td>Description:</td> <td><todo:desc>To Do</todo:desc></td> </tr> <tr> <td> Priority </td> <td> <todo:priority> <select><option>1</option></select> </todo:priority> </td> </tr> <tr> <td> </td> <td> <todo:submit> <button>New</button> </todo:submit> </td> </tr> </table> </lift:TD.add> </lift:Util.in> <lift:Util.out>Please <lift:menu.item name="Login">Log In</lift:menu.item> </lift:Util.out> </lift:surround> ============================================================== C:\www\jetty\webapps\todo\src\main\scala\com\liftworkshop\model \ToDo.scala package com.liftworkshop.model import net.liftweb._ import mapper._ import http._ import SHtml._ import util._ class ToDo extends LongKeyedMapper[ToDo] with IdPK { def getSingleton = ToDo object done extends MappedBoolean(this) object owner extends MappedLongForeignKey(this, User) object priority extends MappedInt(this) { override def defaultValue = 5 override def validations = validPriority _ :: super.validations def validPriority(in: Int): List[FieldError] = if (in > 0 && in <= 10) Nil else List(FieldError(this, <b>Priority must be 1-10</b>)) override def _toForm = Full(select(ToDo.priorityList, Full(is.toString), f => set(f.toInt))) } object desc extends MappedPoliteString(this, 128) { override def validations = valMinLen(3, "Description must be 3 characters") _ :: super.validations } object loc extends MappedPoliteString(this, 63) { override def validations = valMinLen(3, "Location must be 3 characters") _ :: super.validations } } object ToDo extends ToDo with LongKeyedMetaMapper[ToDo] { lazy val priorityList = (1 to 10). map(v => (v.toString, v.toString)) } ========================================================== C:\www\jetty\webapps\todo\src\main\scala\com\liftworkshop\snippet \TD.scala package com.liftworkshop.snippet import com.liftworkshop._ import model._ import net.liftweb._ import http._ import SHtml._ import S._ import js._ import JsCmds._ import mapper._ import util._ import Helpers._ import scala.xml.{NodeSeq, Text} class TD { def add(form: NodeSeq) = { val todo = ToDo.create.owner(User.currentUser) def checkAndSave(): Unit = todo.validate match { case Nil => todo.save ; S.notice("Added "+todo.desc) case xs => S.error(xs) ; S.mapSnippet("TD.add", doBind) } def doBind(form: NodeSeq) = bind("todo", form, "priority" -> todo.priority.toForm, "desc" -> todo.desc.toForm, "loc" -> todo.loc.toForm, "submit" -> submit("New", checkAndSave)) doBind(form) } private def toShow = ToDo.findAll(By(ToDo.owner, User.currentUser), if (QueryNotDone) By(ToDo.done, false) else Ignore[ToDo], OrderBy(ToDo.done, Ascending), OrderBy(ToDo.priority, Descending), OrderBy(ToDo.desc, Ascending)) private def desc(td: ToDo, reDraw: () => JsCmd) = swappable(<span>{td.desc}</span>, <span>{ajaxText(td.desc, v => {td.desc(v).save; reDraw()})} </span>) private def loc(td: ToDo, reDraw: () => JsCmd) = swappable(<span>{td.loc}</span>, <span>{ajaxText(td.loc, v => {td.loc(v).save; reDraw()})} </span>) 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), "loc" -> loc(td, reDraw) )) def list(html: NodeSeq) = { val id = S.attr("all_id").open_! def inner(): NodeSeq = { def reDraw() = SetHtml(id, inner()) bind("todo", html, "exclude" -> ajaxCheckbox(QueryNotDone, v => {QueryNotDone(v); reDraw}), "list" -> doList(reDraw) _) } inner() } } object QueryNotDone extends SessionVar(false) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---