-1

I am using Grails and I am currently faced with this problem.

This is the result of my html table enter image description here

And this is my code from the gsp page

    <tr>
        <th>Device ID</th>
        <th>Device Type</th>
        <th>Status</th>
        <th>Customer</th>   
    </tr>
<tr>
<g:each in = "${reqid}">
        <td>${it.device_id}</td>
</g:each>

<g:each in ="${custname}">
        <td>${it.type}</td>
        <td>${it.system_status}</td>
        <td>${it.username}</td>
</g:each>
    </tr>

So the problem is, how do I format the table such that the "LHCT271 , 2 , Thomasyeo " will be shifted down accordingly? I've tried to add the <tr> tags here and there but it doesn't work.. any help please?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user1790785
  • 53
  • 10
  • We might need some detail, but, my guess is that your logic might be a bit messed up. Ideally, you use one g:each to render a whole row – GalmWing Dec 07 '12 at 03:25
  • How do I put ${reqid} together with ${custname} in one g each tag? Is it possible? – user1790785 Dec 07 '12 at 03:29
  • 2
    you also need a to start each row and a to end each row – GreyBeardedGeek Dec 07 '12 at 03:29
  • 1
    It doesn't help in this case – user1790785 Dec 07 '12 at 03:31
  • 1
    It depends on how your entities are related and how you return your data from the controller. Ideally you return one set of items (like maybe a a list of `Device`) that have other things related to them (like a list of `Customer`). Then you can iterate through the top level list (`devices`) and for each `device` iterate through the list of `customers`. But GreyBeardedGeek is absolutely correct that you MUST have the `` or you will never get new rows. – Kelly Dec 07 '12 at 05:10
  • I'm turning 2 set of items from the controller and they are not related. So is it possible to have 2 set of item in one `g:each in` tag? In this case the `${reqid}` and `${custname}` in one `g:each in` tag – user1790785 Dec 07 '12 at 06:00
  • Why do you want to show them in the same table when they are not related? – david Dec 08 '12 at 21:42

2 Answers2

2

I think you problem is not in the view, but in the controller (or maybe even the domain). You must have some way of knowing that reqid and custname are related if they are in the same table. You must use that to construct an object that can be easily used in a g:each

You are looking for a way to mix columns and rows, and still get a nice table. I'm afraid that is not possible.

Edit

(Sorry, I just saw the last comment.)

You cannot mix two items in a g:each.

Furthermore, if the two things are not related you probably must not put them in the same table. There will be no way for you or for Grails, to know how to properly organize the information

GalmWing
  • 731
  • 1
  • 7
  • 14
1

Do you want to display the first reqid against the first custname (three fields), the second againts the second and so on? And are those collections of same length?

In such case you could try the following:

<tr>
    <th>Device ID</th>
    <th>Device Type</th>
    <th>Status</th>
    <th>Customer</th>   
</tr>
<g:each var="req" in="${reqid}" status="i">
    <tr>
        <td>${req}</td>
        <td>${custname[i].type}</td>
        <td>${custname[i].system_status}</td>
        <td>${custname[i].username}</td>
    </tr>
</g:each>
eugene82
  • 8,432
  • 2
  • 22
  • 30