j2html nesting for tables

618 Views Asked by At

I am trying to use j2html to render a really simple table, but I have gotten completely stuck on the nesting and can not find any docs for this.

Trying to keep this short and to the point, this is the exact html that I want to achieve:

<table border=0>
<tr>
<td style="vertical-align: top">
<b>Some Info:</b>
</td>
<td style="vertical-align: top">
<p>"some fetched info"</p> 
</td>
</tr>
</table>

Now, what I wrote is this (note that this is one of many attempts):

  table(),

 tr(
    b("Some Info: "),
    td().withStyle("vertical-align: top").withText("some fetched info")),
    br()

The result I get is:

<body>
<table>
</table>
<tr>
<b>Some Info: </b>
<td style="vertical-align: top">Some fetched info
</td>
</tr>

I can not seem to get a grasp of the proper nesting for this problem (or how to add the table border attribute for that matter).

I wrote a very short example here hoping that someone could help, thinking that if I just get this one right the whole thing will probably click in my brain.

(Realizing just now I can't close the table bracket that way...)

1

There are 1 best solutions below

0
On

You would need to nest the tr within the table. Also, you can't have b("Some Info: ") directly within tr, it needs to be nested inside a td. Here is how the code should look:

 table(
     tr(
         td().withStyle("vertical-align: top").withText(b("Some Info: ")),
         td().withStyle("vertical-align: top").withText(p("some fetched info"))))