th:attribute at same level as th:each

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

th:attribute at same level as th:each

dstarh
This post was updated on .
I need to be able to do the following:

https://gist.github.com/3714473


the th:attr works on the td but not on the tr. Is there any way to achieve this?
Reply | Threaded
Open this post in threaded view
|

Re: th:attribute at same level as th:each

Zemi
Administrator
Please re-post your code. Try avoding common HTML < tags >
Reply | Threaded
Open this post in threaded view
|

Re: th:attribute at same level as th:each

dstarh
Edited to include link to gist
Reply | Threaded
Open this post in threaded view
|

Re: th:attribute at same level as th:each

Zemi
Administrator
Your code is ok, it should generate a few table rows, one for object, each with a different data-obj-id attribute.

Review that your ${objects} variable is ok and that every object has a non-null id.

On the other hand, looking at the th:fragment attribute, the problem could be in the inclusion elsewhere, first ensure that content is generated well in the original page.
Reply | Threaded
Open this post in threaded view
|

Re: th:attribute at same level as th:each

dstarh
You're right it had to do with the include... I think the issue is in me trying to dry up my code

I have a table:

table
  row
    td    td   td
  /row

/table

When the page first loads i need the table to be drawn and then subsequently the rows will be re-drawn via ajax and I want to re-use the template for the rows

see gist https://gist.github.com/3714598

I think i might be able to solve this by doing the include on the tbody rather than on the tr itself then have a single place to do the iteration
Reply | Threaded
Open this post in threaded view
|

Re: th:attribute at same level as th:each

dstarh
Nope, it fails to iterate via the th:each when I include via the tbody....
Reply | Threaded
Open this post in threaded view
|

Re: th:attribute at same level as th:each

Zemi
Administrator
I'm a bit confused about your code. Why do you repeat the th:each in both pages?

Anyway, try th:substituteby instead of th:include.

And yes, the th:fragment will be better inside the tbody tag.

Something like that:

MAIN FILE
      < tbody th:substituteby="admin/objects/list_partial :: row" >
      < /tbody >

FILE WITH FRAGMENT
     < tbody th:fragment="row" >
        < tr th:each="object : ${objects}" th:attr=data-id=${object.id} >
        ...
        < /tr >
     < /tbody >

Reply | Threaded
Open this post in threaded view
|

Re: th:attribute at same level as th:each

dstarh
Ok what your doing there makes more sense but it means on subsequent requests i'll have to strip out the tbody which i'm not thrilled about since I only need the rows not the body itself.  I really just want the following

< tbody >
   
      include file that loops over rows  
   
< /tbody>

but when I include the file via th:include on the tr it fails.

I'll experiment with moving the whole thing up a level but this just seems overly complicated for doing what is fairly standard in other templating languages