I have a Lift app that's managing its own domain objects in a MongoDB. At one point I had an object with a list of embedded objects and all worked well. My users had many accounts, and I did something like:

private def bindAccountFields(in:NodeSeq, a:Account, isNewAccount:Boolean):NodeSeq = {...}

Then, from my Manage.render snippet:

      user.accounts.isEmpty match {
        case true => <p>You have no accounts configured.</p>
case false => user.accounts.flatMap(bindAccountFields(in, _, false))
      }

I recently wanted to change User.accounts to a Map[String, Account], since accounts are named and should have unique names. So I did that, and changed the above to:

      user.accounts.isEmpty match {
        case true => <p>You have no accounts configured.</p>
case false => user.accounts.flatMap((v:Tuple2[String, Account]) => bindAccountFields(in, v._2, false))
      }

Except, try though I might, I can't seem to eliminate this error:

[error] /home/nolan/Projects/Utterance2/src/main/scala/info/thewordnerd/utterance/snippet/Manage.scala:67: type mismatch;
[error]  found   : Iterable[scala.xml.Node]
[error]  required: scala.xml.NodeSeq
[error] case false => user.accounts.flatMap((v:Tuple2[String, Account]) => bindAccountFields(in, v._2, false))
[error]                                     ^
[error] one error found

bindAccountFields hasn't changed at all. I'm just changing the collection I iterate over to call it, and the parameter it was passed.

Am I missing something obvious? The whole "binding snippets to a collection" thing seems like magic to me. The getting started guide shows it done, but unless I read carelessly, it really doesn't explain how binding works in that situation. Are prefixes bound in order such that each time I call, say, <account.name/> in a form I get the next value bound there? Does that hold true such that I can have an Account.edit and Account.render snippet, both of which bind to <account:name/>, only the edit snippet binds a text field while the render snippet just displays text? So I'd then have to call the snippets in the order I've bound them? Obviously that wouldn't be advisable if my assumption is true, I'm just trying to understand how this particular bit of magic works. :)

Thanks.


--
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@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