Kris, Having a template like (slightly changed from your example so the values to be dynamic):
<lift:Hello.orderList> <order:id/> <order:items> <item:name/> <item:cost/> </order:items> </lift:Hello.orderList> and the Scala code: case class OrderItem(name:String, cost:String) def orderList(xhtml: Group): NodeSeq = { val orderList = OrderItem("first", "9.99$") :: OrderItem("second", "19.99$") :: Nil val content = (xhtml \\ "items").first.descendant println("Content " + content) bind("order", xhtml, "id" -> Text("My order Id"), "items" -> Group(orderList flatMap (elem => bind("item", content, "name" -> Text(elem.name), "cost" -> Text(elem.cost)))) ) } should work just fine (at least for me it does). .... regarding your compile error the flatMap call returns an Iterable[scala.xml.Node] which does not conform with NodeSeq return Type. To fix this you can probably wrap everything into a Group like: private def bindItems(xhtml : NodeSeq, items :java.util.Collection[Item]) : NodeSeq = { Group(items.flatMap(item => bind("item", xhtml, "name" --> Text(item.getName)))) } ... just out of curiosity is there a reason why you;re using java,util.collection and not Scala List, Seq etc? Br's, Marius On Sep 11, 12:16 am, "Kris Nuttycombe" <[EMAIL PROTECTED]> wrote: > Man, I really wish I understood the Scala type system better. > > def list(xhtml : NodeSeq) : NodeSeq = { > val orders = EM.createQuery[Order]("FROM Order").getResultList > orders.flatMap(order => > bind("order", xhtml, > "id" --> Text(order.getId.toString), > "uuid" --> Text(order.getUuid.toString), > "items" --> bindItems((xhtml \\ "items").first.child, > order.getItems)) > ) > } > > private def bindItems(xhtml : NodeSeq, items : > java.util.Collection[Item]) : NodeSeq = { > items.flatMap(item => > bind("item", xhtml, > "name" --> Text(item.getName))) > } > > [WARNING] > /home/knuttycombe/work/gcsi/gcsi-admin/src/main/scala/com/gaiam/gcsi/snippet/Orders.scala:33: > error: type mismatch; > [WARNING] found : Iterable[scala.xml.Node] > [WARNING] required: scala.xml.NodeSeq > [WARNING] items.flatMap(item => > [WARNING] ^ > [WARNING] one error found > > That's the only error, too; the "list" function compiles just fine. > I've tried making that items.flatMap[NodeSeq], adding an explicit cast > .asInstanceOf[NodeSeq] to the results of the binding, and split > bindItems out into a separate function just to try to make things look > as much the same as possible. WTF? > > Kris > > On Wed, Sep 10, 2008 at 2:28 PM, Derek Chen-Becker > > <[EMAIL PROTECTED]> wrote: > > Sorry, forgot about that. You might be able to use Scala's XML processing to > > just get at the children: > > > bind ("item", (xhtml \\ "items").first.child, ...) > > > Kind of ugly. I still can't find the example that David posted but it seemed > > a lot cleaner. > > > Derek > > > On Wed, Sep 10, 2008 at 12:39 PM, Kris Nuttycombe > > <[EMAIL PROTECTED]> wrote: > > >> Hrm. I think that I need to do something extra there to extract and > >> bind against just the <order:items> element to avoid re-binding over > >> the entire contents of the snippet. > > >> Marius, can you expand at all on using snippet attributes for case > >> (1)? I've googled around and looked at all of the template docs I can > >> find and am not really following how to take that approach. > > >> Thanks, > > >> Kris > > >> On Wed, Sep 10, 2008 at 12:08 PM, Derek Chen-Becker > >> <[EMAIL PROTECTED]> wrote: > >> > I think the bind would look something like this (assuming that xhtml is > >> > the > >> > input NodeSeq): > > >> > bind("order", xhtml, "id" --> Text(your_id_here), > >> > "items" --> your_items.flatMap{ item => > >> > bind("item", > >> > xhtml, "name" --> Text(item.name), "cost" --> Text(item.cost)) }) > > >> > I seem to remember David giving an example of a nested bind but I can't > >> > find > >> > it. > > >> > Derek > > >> > On Wed, Sep 10, 2008 at 11:37 AM, Marius <[EMAIL PROTECTED]> > >> > wrote: > > >> >> Hi, > > >> >> 1. You can use snippet attributes. > >> >> 2. You can leave the divs in the template page and "attach" only > >> >> certain attributes from the snippet. Note that Scala XML API is > >> >> immutable but that was never an inconvenience for me :) ... you could > >> >> pattern match them easily. > > >> >> Br's, > >> >> Marius > > >> >> On Sep 10, 8:05 pm, "Kris Nuttycombe" <[EMAIL PROTECTED]> > >> >> wrote: > >> >> > Hi, all, > > >> >> > I'm in the process of moving a Rails app over to Lift, and have a > >> >> > couple of questions about how to achieve a few things that aren't > >> >> > really addressed in the basic template tutorials. > > >> >> > First, I have a situation where I have a list of orders, each of > >> >> > which > >> >> > has some number of items. What would the binding look like for > >> >> > something like the following? > > >> >> > <lift:snippet type="Orders:list"> > >> >> > <order:id>sample_order_id</order:id> > >> >> > <order:items> > >> >> > <item:name>Sample Item</item:name> > >> >> > <item:cost>$0.00</item:cost> > >> >> > </order:items> > >> >> > </lift:snippet> > > >> >> > Secondly, I know that there have been some additions since the > >> >> > discussion on dynamic node attributes > > >> >> > here:http://groups.google.com/group/liftweb/browse_thread/thread/c7fe7b4b3... > > >> >> > What is the best way to go about porting something that looks like > >> >> > this in Rails: > > >> >> > <div style="color:blue;cursor:pointer" > >> >> > onclick="document.getElementById('order_<%= > >> >> > order.id%>').style.display='block';this.style.display='none'">[View > >> >> > Details]</div> > > >> >> > <div id="order_<%= order.id %>" style="display:none"> > >> >> > ... > >> >> > </div> > > >> >> > It seems a bit odd to use different snippet functions to write the > >> >> > onclick and id attributes. I know that I could move the generation of > >> >> > both divs into the snippet, but that won't make our designers happy > >> >> > because they won't be able to play with the functionality in their > >> >> > browsers. > > >> >> > Thanks, > > >> >> > Kris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---