On Fri, Jan 1, 2010 at 5:21 AM, daiwhea <[email protected]> wrote:

> Start to play with lift now. My first issue is a simple guest book.
>
> There are several guest notes in the guest book list page. I want to
> display a reply form under each guest note. But I don't know how to
> bind the reply form to its note record. How can I do with this? I'm
> using Mapper now.
>
> Below is the snippet and list page.
>
> Thanks for your reply and time.
>
> PS. As I was blocked from the google groups. I'm sorry to say that
> maybe I cannot reply to your comment in time. Thanks again in advance.
>
>
> gbook.html:
> <lift:surround with="default" at="content">
>        <h1>Wellcome to my Guest Book</h1>
>        <lift:GuestBook.list >
>                <div>
>                        <p><item:email /></p>
>                        <p><item:title /></p>
>                        <p><item:content /></p>
>                        <item:reply />
>                </div>
>        </lift:GuestBook.list>
>        <lift:embed what="/templates-hidden/gbook/addForm" />
> </lift:surround>
>
> GuestBook.scala:
> class GuestBook {
>
>  // Set up a requestVar to track the GuestNote object for edits and
> adds
>  object noteVar extends RequestVar(new GuestNote())
>  def note = noteVar.is
>
>  def addNote(html: NodeSeq): NodeSeq = {
>    def doAdd() = {
>      if (isValideNote(note)) {
>        note.createdTime(new Date())
>        note.repliedByAdmin(0)
>        note.save
>        S.redirectTo("/gbook")
>      }
>    }
>    def isValideNote(toCheck : GuestNote) : Boolean =
>      List((if (toCheck.title.length == 0) { S.error("You must provide
> a title"); false } else true),
>        (if (toCheck.email.length == 0) { S.error("You must provide a
> email address"); false } else true),
>        (if (toCheck.content.length == 0) { S.error("You must provide
> some note content"); false } else true)
>      ).forall(_ == true)
>
>    bind("note", html,
>     "title" -> SHtml.text(note.title, note.title(_)),
>     "email" -> SHtml.text(note.email, note.email(_)),
>     "content" -> SHtml.textarea(note.content, note.content(_)),
>     "submit" -> SHtml.submit("Add my Note", doAdd))
>  }
>
>  def list(html: NodeSeq): NodeSeq = {
>    toShow.flatMap(item => {
>        curListNote = item
>        bind("item", html,
>          "title" -> item.title,
>          "email" -> item.email,
>          "content" -> item.content,
>          "reply" -> getReplyContent(item)
>        )
>      }
>    )
>  }
>
>  def replyNote(html: NodeSeq): NodeSeq = {
>

val localNote = curListNote // capture the instance for the closures

def doReply() {
  localNote.save()
}

bind("note", html, "replyContent" -> SHtml.textarea(localNote.replyContent,
localNote.replyContent(_)),
                              "submit" -> SHtml.submit("Reply", doReply))
}




>    def doReply() = {
>      println((S.param("id") openOr "")+(S.param("replyContent")
> openOr ""))
>    }
>
>    bind("note", html,
>      "replyContent" -> SHtml.textarea(curListNote.replyContent,
> curListNote.replyContent(_)),
>      "submit" -> SHtml.submit("Reply", doReply)
>    )
>  }
>
>  private def toShow = GuestNote.findAll()
>
>  var curListNote: GuestNote = _
>
>  private def getReplyContent(item: GuestNote) = {
>    if (item.repliedByAdmin == 0) {
>      <div><p>Not replied by admin</p><lift:embed what="/templates-
> hidden/gbook/replyForm" /></div>
>    }
>    else
>      <p>{"Replied by admin at: "+item.replyTime}</p>
>  }
>
> }
>
>
> /templates-hidden/gbook/addForm.html
> <div>
>        <lift:GuestBook.addNote form="post">
>                <div>
>                        <label>Title:</label><note:title />
>                </div>
>                <div>
>                        <label>Email:</label><note:email />
>                </div>
>                <div>
>                        <label>Your Note:</label><note:content />
>                </div>
>                <div><note:submit /></div>
>        </lift:GuestBook.addNote>
> </div>
>
>
>
>
> /templates-hidden/gbook/replyForm.html
> <div>
>        <lift:GuestBook.replyNote form="post">
>                <div>
>                        <label>Your Reply:</label><note:replyContent />
>                </div>
>                <div><note:submit /></div>
>        </lift:GuestBook.replyNote>
> </div>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<liftweb%[email protected]>
> .
> 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
Surf the harmonics

--

You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.


Reply via email to