I'm trying to use a RequestVar to keep the Mapper model that I'm
editing throughout the lifetime of a simple form. Specifically, I'm
adding Users to a Role. The problem is, the RequestVar seems to get
recreated at every step and, I must admit, it's driving me crazy and
I'd appreciate some help.

Here's my snippet code:
  object currentRole extends RequestVar[Role](new Role)

  def addUsers(xhtml: NodeSeq): NodeSeq = {
    val possible = User.findAll().map(user => (user.id.toString,
user.name))
    val current = role.users.map(user => user.id.toString)
    var updated: List[Long] = Nil

    for {
      id <- S.param("id")
      num <- Full(id.toLong)
      e <- Role.find(By(Role.id, num))
    } {
      println(currentRole)
      currentRole(e)
      println(currentRole)
    }

    def loadUsers(ids: List[String]) = {
      updated = ids.map(_.toLong)
    }

    def processUsers() = {
      println(updated)
      println(currentRole)
    }

    bind("entry", xhtml,
      "users" -> SHtml.multiSelect(possible, current, loadUsers(_)),
      "submit" -> SHtml.submit("Update", processUsers)
    )
  }

And the template:
<lift:surround with="default" at="content">
  <lift:ManageRoles.addUsers form="POST">
    <entry:users />
    <entry:submit />
  </lift:ManageRoles.addUsers>
</lift:surround>

And my STDOUT:
com.equalnetworks.model.Role={Parent
Role:=NULL,datacenter=NULL,Name:=,id=-1,Delete:=false,Update:=false,Create:=false,Read:=false}
com.equalnetworks.model.Role={Parent
Role:=NULL,datacenter=NULL,Name:=Customers,id=2,Delete:=false,Update:=false,Create:=false,Read:=false}
INFO - Service request (GET) /roles/memberships/ took 87 Milliseconds
INFO - Service request (GET) /classpath/jquery.js took 7 Milliseconds
INFO - Service request (GET) /images/ajax-loader.gif took 6
Milliseconds
List(1, 2)
com.equalnetworks.model.Role={Parent
Role:=NULL,datacenter=NULL,Name:=,id=-1,Delete:=false,Update:=false,Create:=false,Read:=false}

As you can see, I'm using a for comprehension to take a request
parameter (e.g. /roles/memerships/?id=2) and get a Role, which I then
successfully assign to my currentRole RequestVar (see how id is first
-1 and then 2). Unfortunately once I submit the form processUsers is
called and currentRole again has an id of -1. Why is this?

Thanks in advance,
Peter Robinett
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to