Question

Please excuse if this is a very basic question, I'm learning. :(

I have this class:

class X  {
  def do_something {
    db withSession {
      val qresult = for { 
         (d, o) <- TABLE1 innerJoin TABLE2 on (_.TB1ID === _.TB2ID)
      } yield(d, o)
    }
  }
}

and I would like to build a HTML table out of this, something like:

(record1)  d.TB1ID d.F1VALUE d.F2VALUE o.F1VALUE o.F2VALUE o.TB2ID
(record2)  d.TB1ID d.F1VALUE d.F2VALUE o.F1VALUE o.F2VALUE o.TB2ID
....

would anyone be kind enough to give me a pointer where to look? I've found plenty of examples but I have trouble connecting the qresult value to something I can bind in my template.

I am using Lift and Slick 1.0.1.

Was it helpful?

Solution

Assuming you have a table in your HTML template that looks like this:

<table>
  <tr>
    <td class="TB1ID"></td>
    <td class="dF1VALUE"></td>
    <td class="dF2VALUE"></td>
    <td class="oF1VALUE"></td>
    <td class="oF2VALUE"></td>
    <td class="TB2ID"></td>
  </tr>
</table>

Then, you should be able to have your CSS Transform look like:

"tr" #> qresult.map { case (d, o) =>
  ".TB1ID *" #> d.TB1ID &
  ".dF1VALUE *" #> d.F1VALUE &
  ".dF2VALUE *" #> d.F2VALUE &
  ".oF1VALUE *" #> o.F1VALUE &
  ".oF1VALUE *" #> o.F2VALUE &
  ".TB2ID *" #> o.TB2ID 
}

That will key on the TR and repeat it for every row in your qresult list. Then, for each of the columns (represented above by their class attribute), it will output the value you want associated with it. Note that the * in the selector will append the value on the right as a child of the TD instead of replacing it with the value on the right.

You can find more information on CSS Selectors and outputting HTML here:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top