0

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.

jcern
  • 7,798
  • 4
  • 39
  • 47
Will I Am
  • 2,614
  • 3
  • 35
  • 61

1 Answers1

1

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:

jcern
  • 7,798
  • 4
  • 39
  • 47
  • Thank you, I got it to work. Apparently I had to call .list on the qresult before using your example above, but otherwise it seems to be working great. Thank you. – Will I Am Oct 03 '13 at 04:29
  • By the way, how would you do this if I wanted to have a template within a template? For example, assume that d.F2VALUE above was an array of n pictures, so I want to insert n pictures into the table cell identified by .dF2VALUE? – Will I Am Oct 03 '13 at 23:05
  • Essentially you'd do it the same way as you handled the TR row above: `.dF2VALUE *" #> d.F2VALUE.map{ n => ".ele" #> n.value }`. If you have a more specific example you want to see, just post a new question and I can give you a more complete answer. – jcern Oct 04 '13 at 00:50
  • thanks! i am going to try to figure it out on my own before bugging ya. – Will I Am Oct 04 '13 at 01:11
  • Well,I got stuck at how to aggregate the items that have duplicate keys :( If you have time, my new question is here: http://stackoverflow.com/questions/19173423/lift-grouping-items-during-css-selector-transform – Will I Am Oct 04 '13 at 04:53