Hello everyone,
I'm having some problems with making the MetaMegaProtoUser "edit"
method templateable (because I believe in the concept of separating
content and design) and am succeeding quite well, except for with one
little detail: I can't make my changes in the edit form persistent; it
seems that the "User" instance gets lost somewhere in the process and
that all the client-side changes therefore also get lost.

The code is at the end of the message. The edit method is called with
a template which also is at the very end of the message.

I would really appreciate if anyone with more Lift experience than me
could spot the mistake, because I simply cannot find it.

-------------------------------------------------------------------------------------------------
The "snippet" (inside a subclass of MetaMegaProtoUser):

  /** Create an edit form with the specified template */
  def edit(xhtml: NodeSeq) = {
    val theUser: User = currentUser.open_! // we know we're logged in

    def testEdit() {
      theUser.validate match {
        case Nil =>
          theUser.save
          S.notice("Profile updated") //The Lift Core has a spelling
mistake in its translation, so I don't use S.??
          S.redirectTo(homePage)

        case xs =>
          S.error(xs)
          S.mapSnippet(S.currentSnippet.open_!, innerEdit)
      }
    }

    def innerEdit(t: NodeSeq) = bind("user", t,
                                "field" -> ((h: NodeSeq) => localForm
(h, theUser, true)),
                                "submit" -> SHtml.submit(S.??("edit"),
testEdit _))
    innerEdit(xhtml)
  }

  /** Make a form with all the editable fields of an user, from a
template */
  protected def localForm(xhtml: NodeSeq, user: User, ignorePassword:
Boolean): NodeSeq = {
    signupFields
      .map(fi => getSingleton.getActualBaseField(user, fi)) //get
actual fields
      .filter(f => !ignorePassword || (f match { //remove the password
field
        case f: MappedPassword[_] => false
        case _ => true
      }))
      .flatMap(f =>
          bind("field", xhtml,
            "name" -> Text(f.displayName),
            "form" -> f.toForm)
        )
  }

-------------------------------------------------------------------------------------------------
The template:

<lift:surround with="default" at="content">
    <lift:User.edit form="POST">
        <table>
            <tbody>
                <user:field>
                    <tr>
                        <td><field:name/></td>
                        <td><field:form/></td>
                    </tr>
                </user:field>
            </tbody>
            <tfoot>
                <tr>
                    <td>&nbsp;</td>
                    <td><user:submit/></td>
                </tr>
            </tfoot>
        </table>
    </lift:User.edit>
</lift:surround>

--~--~---------~--~----~------------~-------~--~----~
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