Hi,
    I was looking over the JsonHandler stuff and it looks pretty
interesting. I thought I'd try it out for a member add page on my latest
project, but I can't figure out how to pass state through the snippet.
Basically, I have a "Team" object that I want to add coaches (Member
objects) to. I was thinking that I could present a JSON form with a name
input so that people could search by name; you'd hit search and the JSON
handling would search for members matching the given name and present them
as a table of users, each with an "Add" link next to them. It's the add link
that I'm having trouble with. I need to be able to access both the member
and the team object when I do the add, but I'm not sure how to pass the Team
object along. I have a couple of ideas:


   1. Use a stateful snippet - seems easy but it also seems a little heavy
   for just one method out of many on this snippet class.
   2. Add the current team to the session - seems really ugly and is
   somewhat equivalent to #1

It's early so I may be overthinking this or overlooking something completely
obvious. Or am I completely abusing JSON forms? Should I be making this a
COMET page instead? For reference, the code follows. Teams.passedTeam is a
RequestVar[Can[Team]] that defaults to Empty.

Thanks,

Derek

  import JsCmds._
  object jsonCoach extends JsonHandler {
    def performAdd (coach : Member, teamDet : Team) = {
      val team = Model.merge(teamDet)
      team.coaches.add(Model.getReference(classOf[Member], coach.id))
      Teams.passedTeam(Full(team))
    }

    def apply(in : Any): JsCmd =
      SetHtml("json_result", in match {
    case j @ JsonCmd("processForm", _, p: Map[String, _], _) => {
      val members = Model.findAll[Member]("memberLikeUserId", "userId" ->
p("name"))

      val table : NodeSeq = members.flatMap({member =>
        <tr>
          <td>{member.userId}</td>
          <td>{member.name}</td>
              <td>{link("viewTeam", () => performAdd(member,
Teams.passedTeam.is.open_!), Text("Add"))}</td> // TODO: This can't be right
            </tr>
      })

      <table class="display">
        <tr>
          <th>User ID</th>
          <th>Name</th>
          <th></th>
            </tr>
        { table }
      </table>
    }
    case x => <b>Problem handling search</b>
      })
  }

  def addCoachForm (xhtml : NodeSeq) : NodeSeq = jsonForm(jsonCoach, xhtml)
  def addCoachHead = <head>{Script(jsonCoach.jsCmd)}</head>

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to