scalahtml-tablecometlift

Comet tables with Lift 2.4 and HTML5


I'm trying to dynamically update a HTML table via Comet. I've got something like the following:

class EventsComet extends CometClient[Event] {
  def server = Event

  def render = {
    println("Binding on: " + defaultHtml)
    data.flatMap( event =>
      bind("event", "name" -> event.name.toString, "date" -> event.startDate.toString)
    )
  }
}

And:

<lift:comet type = "EventsComet">
    <table>
        <thead>
            <tr>
                <th>Name</th>
                <th>Date</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><event:name />Test Name</td>
                <td><event:date />Oct. 25, 2012</td>
            </tr>
        </tbody>
    </table>
</lift:comet>

This prints out the entire table over and over again, one for each event rendered by EventsComet. The println statement outputs the entire table node.

So I tried variations:

<table>
    <thead>
        <tr>
            <th>Race</th>
            <th>Track</th>
            <th>Date</th>
        </tr>
    </thead>
    <tbody>
        <lift:comet type = "EventsComet">
            <tr>
                <td><event:name />Test Name</td>
                <td><event:date />Oct. 25, 2012</td>
            </tr>
        </lift:comet>
    </tbody>
</table>

As expected, the HTML5 parser strips out the [lift:comet] tags and no binding occurs.

So I tried switching the rows to:

<tr lift:comet = "EventsComet">
    <td><event:name />Test Name</td>
    <td><event:date />Oct. 25, 2012</td>
</tr>

...as is shown in a snippet example here, but with this syntax my CometClient is not being instantiated at all.

Can anyone advise on the proper syntax?

EventsComet itself works fine; it can keep lists of events up to date without problem. I only run into issue using tables (and presumably other highly-nested structures I've not tried yet?).

Thank you. This is all rather frustrating for such a simple problem, and makes me want to just start implementing my templates in a strongly-typed templating language instead of using bindings.


Solution

  • The proper syntax seems to be:

    <tr class="lift:comet?type=EventsComet">
        <td><event:name />Test Name</td>
        <td><event:date />Oct. 25, 2012</td>
    </tr>
    

    From this thread: https://groups.google.com/forum/?fromgroups=#!topic/liftweb/NUDU1_7PwmM

    Sometimes I'm getting duplicate rows (inserted above the table header at that), but I'd imagine this is related to my comet actor itself.